0

first of all i know there are already two post dealing with the same issue. But none of their solutions worked for me. Error inflating class android.widget.listview and Android App Stopped Error :inflating class android.widget.ListView

In my case the error also happens when setContentView() of the onCreate() of my Activity get´s called. This is the exception:

E/ChecklistActivity: Binary XML file line #5 in de.bigunet.varionote:layout/activity_checklist: Binary XML file line #5 in de.bigunet.varionote:layout/activity_checklist: Error inflating class android.widget.ListView
W/System.err: android.view.InflateException: Binary XML file line #5 in de.bigunet.varionote:layout/activity_checklist: Binary XML file line #5 in de.bigunet.varionote:layout/activity_checklist: Error inflating class android.widget.ListView
W/System.err: Caused by: android.view.InflateException: Binary XML file line #5 in de.bigunet.varionote:layout/activity_checklist: Error inflating class android.widget.ListView
W/System.err: Caused by: java.lang.reflect.InvocationTargetException
W/System.err:     at java.lang.reflect.Constructor.newInstance0(Native Method)
W/System.err:     at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
W/System.err:     at android.view.LayoutInflater.createView(LayoutInflater.java:852)
W/System.err:     at android.view.LayoutInflater.createView(LayoutInflater.java:774)
W/System.err:     at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
W/System.err:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:928)
W/System.err:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:948)
W/System.err:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1002)
W/System.err:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
W/System.err:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
W/System.err:     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
W/System.err:     at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
W/System.err:     at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
W/System.err:     at com.bigunet.varionote.ChecklistActivity.onCreate(ChecklistActivity.java:46)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8207)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8191)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3800)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4003)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2317)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:246)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:8595)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
W/System.err: Caused by: android.content.res.Resources$NotFoundException: Text array resource ID #0x7f0c0032
W/System.err:     at android.content.res.Resources.getTextArray(Resources.java:728)
W/System.err:     at android.content.res.TypedArray.getTextArray(TypedArray.java:1063)
W/System.err:     at android.widget.ListView.<init>(ListView.java:269)
W/System.err:     at android.widget.ListView.<init>(ListView.java:258)
W/System.err:     at android.widget.ListView.<init>(ListView.java:254)
W/System.err:   ... 32 more

Here is the onCreate() of my Activity:

public class ChecklistActivity extends AppCompatActivity {
    private static final String TAG = "ChecklistActivity";

    private ChecklistAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_checklist);

                adapter = new ChecklistAdapter(this);
                checkListView = (ListView) findViewById(R.id.checkList);
                checkListView.setAdapter(adapter);
                checkListView.setEnabled(true);
            }
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        }
    }
}

Here´s the xml for the activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView android:id="@+id/checkList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:entries="@layout/checklist_item">
    </ListView>

</RelativeLayout>

And here is the xml for the checklist_item:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutChecklistItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:padding="10dp"
    android:focusable="true">

    <TextView
        android:id="@+id/textViewCheckText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:clickable="true"
        android:padding="5dp"
        android:text="@string/checktext"
        android:textColor="@color/black"
        android:textSize="40sp"
        android:focusable="true" />

    <TextView
        android:id="@+id/textViewCheckWert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textViewCheckText"
        android:layout_alignStart="@+id/textViewCheckText"
        android:layout_alignParentEnd="true"
        android:clickable="true"
        android:padding="5dp"
        android:text="@string/checkwert"
        android:textSize="25sp"
        android:textStyle="italic"
        android:typeface="normal"
        android:focusable="true" />

</RelativeLayout>

I realy don´t get what´s wrong here... I would be interested if you guys run into the same problem as i do. Or am i missing something? Any help on this would be great! Thanks in advance.

Morris

MorrisF
  • 11
  • 4
  • `android:entries="@layout/checklist_item"` – The `entries` attribute does not take a `@layout` resource. It's expecting an `@array`; a pre-defined list of its items, basically. Btw, please post the complete stack trace for issues like this. The actual error is not even hinted at in those three lines you extracted from it. – Mike M. Feb 23 '22 at 16:22
  • Thanks for your answer. how do i pre define a list of items? – MorrisF Feb 24 '22 at 08:01
  • If you're wanting to use your `ChecklistAdapter`, you can't. That attribute is for simple, single-`TextView` items in an `ArrayAdapter` that's handled internally. – Mike M. Feb 24 '22 at 08:05
  • I dont realy know what you mean sorry. but i just added the whole exception to the post – MorrisF Feb 24 '22 at 10:20
  • Do i have to create a new directory in res called array and move checklist_item.xml to that directory? – MorrisF Feb 24 '22 at 12:55
  • Yeah, sorry, I should've explicitly said that you likely shouldn't be using that attribute at all, instead of just pointing out that it's being used incorrectly. I often forget that others usually aren't following the same line of thought that I am. :-) – Mike M. Feb 24 '22 at 18:58
  • No problem! :) Still your answer led me into the right direction – MorrisF Feb 25 '22 at 13:00

1 Answers1

0

Just solved it!

I simply removed

android:entries="@layout/checklist_item"

from the xml of my activity and now it works fine.

MorrisF
  • 11
  • 4