我不知道我做了什么,但我的應用程式不再作業 - 你能幫忙嗎?
這是我嘗試啟動應用程式時得到的 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)
[...]
在我的 manifests.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() }
}
}
uj5u.com熱心網友回復:
你用的是什么主題?您是否嘗試過先洗掉 appbarlayout 以查看它是否崩潰?您可能需要在應用程式中使用材料主題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/411478.html
標籤:
