Home > Mobile >  Kotlin App stopped working (LOGCAT included) - I am a Beginner in Coding
Kotlin App stopped working (LOGCAT included) - I am a Beginner in Coding

Time:01-15

I dont know what I did, but my App doesnt work anymore - Can you help ?

This is the first lines of the Logcat that I get when i try starting the App

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)

[...]

And in my manifests.xml file there is something underlined, I dont know if it is important? enter image description here

 <?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>

In Case you need this file too

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() }
    }
}

CodePudding user response:

What theme are you using? Have you tried removing the appbarlayout first to see if it crash? And you might need to use material theme in your application

  •  Tags:  
  • Related