Kotlin应用程序停止工作(包括LOGCAT)-我是编码初学者



我不知道我做了什么,但我的应用程序已经不工作了-你能帮忙吗

这是我尝试启动应用时得到的Logcat的第一行

2022-01-14 17:17:10.138 14076-14076/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.wit.location, PID: 14076
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.wit.location/org.wit.location.activities.LocationList}: android.view.InflateException: Binary XML file line #16 in org.wit.location:layout/list_of_locations: Binary XML file line #16 in org.wit.location:layout/list_of_locations: Error inflating class com.google.android.material.appbar.AppBarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

[…]

在我的manifest.xml文件中有一些下划线,我不知道它是否重要?在此处输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.wit.location.activities.LocationList">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:fitsSystemWindows="true"
app:elevation="0dip"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@color/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

如果您也需要此文件

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import org.wit.location.R
import org.wit.location.adapters.LocationAdapter
import org.wit.location.adapters.LocationListener
import org.wit.location.databinding.ListOfLocationsBinding
import org.wit.location.main.MainApp
import org.wit.location.models.Location_Model
class LocationList : AppCompatActivity(), LocationListener {
lateinit var app: MainApp
private lateinit var binding: ListOfLocationsBinding
private lateinit var refreshIntentLauncher : ActivityResultLauncher<Intent>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ListOfLocationsBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.toolbar.title = title
setSupportActionBar(binding.toolbar)
app = application as MainApp
val layoutManager = LinearLayoutManager(this)
binding.recyclerView.layoutManager = layoutManager
binding.recyclerView.adapter = LocationAdapter(app.locations.findAll(),this)

registerRefreshCallback()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.mainmenu, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.item_add -> {
val launcherIntent = Intent(this, BasicLocation::class.java)
refreshIntentLauncher.launch(launcherIntent)
}
}
return super.onOptionsItemSelected(item)
}
override fun onLocationClick(location: Location_Model) {
val launcherIntent = Intent(this, BasicLocation::class.java)
launcherIntent.putExtra("location_edit", location)
refreshIntentLauncher.launch(launcherIntent)
}
private fun registerRefreshCallback() {
refreshIntentLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult())
{ binding.recyclerView.adapter?.notifyDataSetChanged() }
}
}

您使用的主题是什么?你有没有试着先删除appbarlayout看看它是否崩溃?您可能需要在应用程序中使用材料主题

最新更新