这是此问题的后续内容 - Debug NullPointerException
我修复了nullpointexception错误,我的应用程序正确启动。但现在......当我选择"播放列表按钮"应用程序崩溃。我已经研究过这个错误,但是找不到多少。我也试过自己修理但没有运气。我在看logcat,它显示了很多错误,但没有一个提到我的代码?当我慢慢地浏览它时,我注意到Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ListView
,在那里我浏览了列表并看到了at com.ascendapps.nexplay.PlayListActivity.onCreate(PlayListActivity.java:23)
。
所以我去了我的代码并查看了该行,但我不知道导致此错误的原因是什么?
在代码行23中显示setContentView(R.layout.playlist);
。
我的全班 -
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();
}
});
}
}
这是我的完整logcat以防我错过了什么?
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
请帮助我,我真的想要建立一个属于我自己的音乐播放器,我已经尝试过搜索并尝试不同的事情。
编辑:
<?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>