我试图在Android中创建一个带有列表的应用程序!
我正在从我的数据库中获取我想要的数据,现在我试图将其放入listview
我尝试按照教程进行操作。
现在我为自己构建一个应用程序,我的应用程序在启动时崩溃是我的活动代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.activity_stats);
setContentView(R.layout.activity_stats);
ListView listContent = (ListView)findViewById(R.id.listShit);
ArrayList<HashMap<String, String>> shitList = dbTools.getAllShits();
dbTools.getAllShits();
if(shitList.size()!=0) {
ListAdapter adapter = new SimpleAdapter( stats.this,shitList, R.id.shit_entry, new String[] { "shitId","earned"}, new int[] {R.id.shitId, R.id.earned});
setListAdapter(adapter);
}
logcat
8-11 21:29:47.718 29617-29617/jmsbrk.crappapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: jmsbrk.crappapp, PID: 29617
java.lang.RuntimeException: Unable to start activity ComponentInfo{jmsbrk.crappapp/jmsbrk.crappapp.stats}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ListActivity.onContentChanged(ListActivity.java:243)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
at android.app.Activity.setContentView(Activity.java:1973)
at jmsbrk.crappapp.stats.onCreate(stats.java:36)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
如果您正在扩展ListActivity,Android默认会尝试搜索ID为“@android:id / list”的Listview。确保你正在设置它。
一个基本的例子是:
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>