0

This is a followup of this question - Debug NullPointerException

I have fixed the nullpointexception error and my application launches properly. But now... When I select the "Playlist button" The application crashes. I've researched on this error but couldn't find much. I also tried fixing it myself but no luck. I was looking at the logcat and it showed loads of errors but none of them referred to the code I had? When going through it slowly, I noticed Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ListView, form there I went through the list and saw at com.ascendapps.nexplay.PlayListActivity.onCreate(PlayListActivity.java:23).

So I went to my code and check the line, but I have no clue what's causing this error? In the code line 23 displays setContentView(R.layout.playlist);.

My full class -

import java.util.ArrayList;
import java.util.HashMap;
import com.ascendapps.nexplay.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class PlayListActivity extends ListActivity {
    // Songs list
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.playlist);

        ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();

        SongsManager plm = new SongsManager();
        // get all songs from sdcard
        this.songsList = plm.getPlayList();

        // looping through playlist
        for (int i = 0; i < songsList.size(); i++) {
            // creating new HashMap
            HashMap<String, String> song = songsList.get(i);

            // adding HashList to ArrayList
            songsListData.add(song);
        }

        // Adding menuItems to ListView
        ListAdapter adapter = new SimpleAdapter(this, songsListData,
                R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
                        R.id.songTitle });

        setListAdapter(adapter);

        // selecting single ListView item
        ListView lv = getListView();
        // listening to single listitem click
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting listitem index
                int songIndex = position;

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),
                        MainActivity.class);
                // Sending songIndex to PlayerActivity
                in.putExtra("songIndex", songIndex);
                setResult(100, in);
                // Closing PlayListView
                finish();
            }
        });
    }
}

And this is my full logcat in-case I missed anything?

04-06 17:42:51.774: W/ResourceType(12387): CREATING STRING CACHE OF 72 bytes
04-06 17:42:51.854: I/Adreno-EGL(12387): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
04-06 17:42:51.874: D/OpenGLRenderer(12387): Enabling debug mode 0
04-06 17:42:51.924: I/ActivityManager(12387): Timeline: Activity_idle id: android.os.BinderProxy@42308b80 time:51348547
04-06 17:42:54.684: I/ActivityManager(12387): Timeline: Activity_launch_request id:com.ascendapps.nexplay time:51351305
04-06 17:42:54.704: W/ResourceType(12387): CREATING STRING CACHE OF 72 bytes
04-06 17:42:54.764: E/ActivityThread(12387): Failed to inflate
04-06 17:42:54.764: E/ActivityThread(12387): android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ListView
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
04-06 17:42:54.764: E/ActivityThread(12387):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-06 17:42:54.764: E/ActivityThread(12387):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:344)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.Activity.setContentView(Activity.java:1945)
04-06 17:42:54.764: E/ActivityThread(12387):    at com.ascendapps.nexplay.PlayListActivity.onCreate(PlayListActivity.java:23)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.Activity.performCreate(Activity.java:5351)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.ActivityThread.access$800(ActivityThread.java:145)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.os.Handler.dispatchMessage(Handler.java:102)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.os.Looper.loop(Looper.java:136)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.app.ActivityThread.main(ActivityThread.java:5078)
04-06 17:42:54.764: E/ActivityThread(12387):    at java.lang.reflect.Method.invokeNative(Native Method)
04-06 17:42:54.764: E/ActivityThread(12387):    at java.lang.reflect.Method.invoke(Method.java:515)
04-06 17:42:54.764: E/ActivityThread(12387):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
04-06 17:42:54.764: E/ActivityThread(12387):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-06 17:42:54.764: E/ActivityThread(12387):    at dalvik.system.NativeStart.main(Native Method)
04-06 17:42:54.764: E/ActivityThread(12387): Caused by: java.lang.reflect.InvocationTargetException
04-06 17:42:54.764: E/ActivityThread(12387):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-06 17:42:54.764: E/ActivityThread(12387):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
04-06 17:42:54.764: E/ActivityThread(12387):    ... 24 more
04-06 17:42:54.764: E/ActivityThread(12387): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020009
04-06 17:42:54.764: E/ActivityThread(12387):    at android.content.res.Resources.loadDrawable(Resources.java:2126)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.widget.AbsListView.<init>(AbsListView.java:807)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.widget.ListView.<init>(ListView.java:146)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.widget.ListView.<init>(ListView.java:142)
04-06 17:42:54.764: E/ActivityThread(12387):    ... 27 more
04-06 17:42:54.764: E/ActivityThread(12387): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #7: <item> tag requires a 'drawable' attribute or child tag defining a drawable
04-06 17:42:54.764: E/ActivityThread(12387):    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:181)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
04-06 17:42:54.764: E/ActivityThread(12387):    at android.content.res.Resources.loadDrawable(Resources.java:2122)
04-06 17:42:54.764: E/ActivityThread(12387):    ... 31 more
04-06 17:42:54.764: D/AndroidRuntime(12387): Shutting down VM
04-06 17:42:54.764: W/dalvikvm(12387): threadid=1: thread exiting with uncaught exception (group=0x41fd7c80)
04-06 17:42:54.764: E/AndroidRuntime(12387): FATAL EXCEPTION: main
04-06 17:42:54.764: E/AndroidRuntime(12387): Process: com.ascendapps.nexplay, PID: 12387
04-06 17:42:54.764: E/AndroidRuntime(12387): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ascendapps.nexplay/com.ascendapps.nexplay.PlayListActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ListView
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread.access$800(ActivityThread.java:145)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.os.Handler.dispatchMessage(Handler.java:102)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.os.Looper.loop(Looper.java:136)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread.main(ActivityThread.java:5078)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at java.lang.reflect.Method.invokeNative(Native Method)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at java.lang.reflect.Method.invoke(Method.java:515)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at dalvik.system.NativeStart.main(Native Method)
04-06 17:42:54.764: E/AndroidRuntime(12387): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ListView
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:344)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.Activity.setContentView(Activity.java:1945)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at com.ascendapps.nexplay.PlayListActivity.onCreate(PlayListActivity.java:23)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.Activity.performCreate(Activity.java:5351)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
04-06 17:42:54.764: E/AndroidRuntime(12387):    ... 11 more
04-06 17:42:54.764: E/AndroidRuntime(12387): Caused by: java.lang.reflect.InvocationTargetException
04-06 17:42:54.764: E/AndroidRuntime(12387):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
04-06 17:42:54.764: E/AndroidRuntime(12387):    ... 24 more
04-06 17:42:54.764: E/AndroidRuntime(12387): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020009
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.content.res.Resources.loadDrawable(Resources.java:2126)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.widget.AbsListView.<init>(AbsListView.java:807)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.widget.ListView.<init>(ListView.java:146)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.widget.ListView.<init>(ListView.java:142)
04-06 17:42:54.764: E/AndroidRuntime(12387):    ... 27 more
04-06 17:42:54.764: E/AndroidRuntime(12387): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #7: <item> tag requires a 'drawable' attribute or child tag defining a drawable
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:181)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
04-06 17:42:54.764: E/AndroidRuntime(12387):    at android.content.res.Resources.loadDrawable(Resources.java:2122)
04-06 17:42:54.764: E/AndroidRuntime(12387):    ... 31 more
04-06 17:42:56.674: I/Process(12387): Sending signal. PID: 12387 SIG: 9

Please help me out, I'm really wanting to build a music player of my own, I've tried searching and trying different things it never works.

Edit:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item
 android:state_selected="false"
    android:state_pressed="false"
    android:color="#222222" />
<item android:state_pressed="true"
    android:color="#d8d8d8" />
<item android:state_selected="true"
 android:state_pressed="false"
    android:color="#d8d8d8" />
</selector>
Community
  • 1
  • 1

1 Answers1

3

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020009

You do not have a resource by the name list_selector.xml under res/drawable. Check that and fix it.

Edit :

At the last you have

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line 7: tag requires a 'drawable' attribute or child tag defining a drawable

You probably should be looking at the list_selector.xml and it says item tag requires a drawable attribute which is missing.

Missing

 <item
 android:drawable="@drawable/yourdrawable" 

You can check this

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Edit 2:

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list.

You require a ListView in playlist.xml with id as below

 <ListView android:id="@android:id/list"

Quoting docs

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • I've checked my res/drawable and can confirm "list_selector.xml" is present. – Little Plastic Soldier Apr 06 '14 at 08:38
  • 1
    @LittlePlasticSoldier the second part of the stacktrace says that you require a drawable attribute which is missing in `list_selector.xml` and pls don't post links to external source. Is it so hard posting the code here – Raghunandan Apr 06 '14 at 08:39
  • Oh sorry, I just thought it makes it less crowded and long. Wait so there is a missing attribute within the .xml file? By any chance what could it be :S The guide mentioned to copy their code and paste it and I did. – Little Plastic Soldier Apr 06 '14 at 08:42
  • @LittlePlasticSoldier the activity code is of no use here while the stacktrace and the selector xml is required. – Raghunandan Apr 06 '14 at 08:44
  • Oh not to worry, I fixed the .xml by changing it from android:color to android:drawble and gave it a correct path to the colors.xml with the correct colors. This reduced all of the errors. And leaves me with one error - Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list. Which is in PLayListActivity – Little Plastic Soldier Apr 06 '14 at 08:48
  • Thank you, that worked. But for some reason the listView isn't showing any files (.mp3) – Little Plastic Soldier Apr 06 '14 at 08:59
  • @LittlePlasticSoldier that is a different problem. post a differen question. The problem is in activity code – Raghunandan Apr 06 '14 at 09:00
  • Thanks Ill ask it as a different question as later as I'm trying other ways for this to work. – Little Plastic Soldier Apr 06 '14 at 09:02