他们给我发了一个项目,但我无法编译它。工作室抛出错误:
Keystore file 'путь к файлу ключа.jks' not found for signing config 'config'.
我是否必须向项目的创建者索取密钥文件,还是可以在没有签名密钥的情况下进行编译?
他们给我发了一个项目,但我无法编译它。工作室抛出错误:
Keystore file 'путь к файлу ключа.jks' not found for signing config 'config'.
我是否必须向项目的创建者索取密钥文件,还是可以在没有签名密钥的情况下进行编译?
在主activity的fragment内部,当从FireBase加载数据时,会检查用户是否拥有所有必要的数据,如果没有,则将他发送到所需的activity输入数据。当用户到达所需的活动时,他可以在不同的活动之间切换以输入不同的信息(学校->班级->时间表)
并且由于某种原因,在与学校的活动中,在选择学校时,会弹出一个错误,该错误位于主要活动的片段中。
kotlin.TypeCastException: null cannot be cast to non-null type com.example.kotlindiary.MainActivity
at com.example.kotlindiary.MainFragment$downloadHomework$1$onDataChange$1.onDataChange(MainFragment.kt:210)
抱怨 Intent 初始化的行:
if(timetableisreal){...}
else{
val intent = Intent(activity, SetTimetableActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
}
我注意到选择学校时会弹出错误,并将错误发送到主片段。我假设 ValueEventListener 多次运行此代码,此时发生错误。但是奇怪的是,在主要活动完成后,监听器继续工作。提前致谢
UPD:片段代码
class MainFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
...
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
...
downloadHomework()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
}
fun downloadHomework(){
...
ref.addValueEventListener(object : ValueEventListener{
override fun onDataChange(p0: DataSnapshot) {
user = p0.getValue(User::class.java)
val schoolName = user?.school
val form = user?.form
if(user?.name == "" || user?.surname == ""){//проверка, есть ли имя, фамилия
val intent = Intent(activity, ProfileActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
(activity as MainActivity).finish()
}
else if(schoolName == ""){//выбрана ли школа
val intent = Intent(activity, ChooseSchoolActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
(activity as MainActivity).finish()
}
else if(form == ""){//выбран ли класс
val intent = Intent(activity, ChooseFormActivity::class.java)
intent.putExtra("schoolName", schoolName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
(activity as MainActivity).finish()
}
else{
val refTimetable = FirebaseDatabase.getInstance().getReference("/schools/$schoolName/$form/timetable")
refTimetable.addValueEventListener(object : ValueEventListener{
override fun onDataChange(p0: DataSnapshot) {
p0.children.forEach {
//проверка, есть ли расписание
}
if(timetableisreal){...}
else{
val intent = Intent(activity, SetTimetableActivity::class.java)//если нет, отправляем на активити с установкой расписания
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
}
}
override fun onCancelled(p0: DatabaseError) {}
})
}
}
override fun onCancelled(p0: DatabaseError) {}
})
}
}
需要设置工具栏样式:MaterialComponents.ActionBar.Surface
表面颜色设置为#f6f6f6,甚至工作室本身也显示出来,如截图所示:背景:#f6f6f6
但是在设计和手机上,ToolBar 设置为 PrimaryColor (#000000),在样式文件中设置
我检查了代码,工具栏的颜色没有在任何地方设置。这只能通过在标签内显式设置背景颜色来处理。该怎么办?
xml代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorlayout"
android:background="#e5e5e5"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/ToolBar_Main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/Widget.MaterialComponents.ActionBar.Surface"
/>
</com.google.android.material.appbar.AppBarLayout>
一维数组可以方便地直接在代码中填充:
var array = emptyArray<String>()
array += "строка"
但是在二维数组的情况下var array = Array(7, {emptyArray<String>()})
,我没有找到有关在不借助计数器和其他拐杖的情况下填充数组如何方便的信息。array[position] += "строка"
不会再工作了。如何解决这个问题呢?
打开BottomSheetBehavior
重叠RecyclerView
和BottomNavigation
(第一张图片)。同时,如果将带有BottomSheet的布局移到FrameLayout之后,<include layout="@layout/layout_bottom_sheet_main" />
则只有导航栏重叠(第二张图)。如何解决问题?
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<include layout="@layout/layout_bottom_sheet_main" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/ToolBar_Main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/bottom_navigation_menu"/>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
android:layout_marginTop="?attr/actionBarSize"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我正在学习 kotlin 并遇到了问题。
输入是一个由不带空格的整数组成的字符串。有必要找到偶数的总和并将算法作为一个单独的函数来实现。
请注意,对于第 660308340 行,输出将为 24 (6+6+8+4)。
一切都会好的,但只是在循环中出于某种原因我总是添加 54,并且这一行的输出变为 360。
为了检查,我在循环中添加了当前处理的数字 (i) 的值的输出和值 b。i 显示正确,但此处 b 由于某种原因,每次新通过都会增加 54
fun calculateEvenDigits(input:String): Int{
var b = 0
for(i in input){
if (i.toInt() % 2 == 0){
b+=i.toInt()
println("i = $i, b = $b")
}
}
return b
}
fun main(args: Array<String>) {
val a : String? = readLine()
if(a!=null){
print(calculateEvenDigits(a.toString()))
}
}