每当一个按钮打开 About 类时,应用程序就会强制关闭。我完全按照视频教程进行操作,所以应该没有任何错误。
所以我基本上想要一个包含三个项目的列表。然后,当您单击它们时,它将带您进入特定活动。那么有什么遗漏吗?我知道我没有设置任何 onClickListeners,但我只想在继续之前让这个列表正常工作。
这是java文件:
package com.heavyfork.sq;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
public class About extends ListActivity {
protected String[] aboutList = {
"More Apps",
"About",
"Help"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, aboutList);
setListAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.about, menu);
return true;
}
}
和 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".About" >
<ListView
android:id="@+id/aboutList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
日志猫:
05-09 18:01:27.936: E/AndroidRuntime(16943): FATAL EXCEPTION: main
05-09 18:01:27.936: E/AndroidRuntime(16943): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.heavyfork.sq/com.heavyfork.sq.About}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2312)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread.access$600(ActivityThread.java:156)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1250)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.os.Looper.loop(Looper.java:137)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread.main(ActivityThread.java:5229)
05-09 18:01:27.936: E/AndroidRuntime(16943): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 18:01:27.936: E/AndroidRuntime(16943): at java.lang.reflect.Method.invoke(Method.java:525)
05-09 18:01:27.936: E/AndroidRuntime(16943): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
05-09 18:01:27.936: E/AndroidRuntime(16943): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
05-09 18:01:27.936: E/AndroidRuntime(16943): at dalvik.system.NativeStart.main(Native Method)
05-09 18:01:27.936: E/AndroidRuntime(16943): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-09 18:01:27.936: E/AndroidRuntime(16943): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.Activity.setContentView(Activity.java:1889)
05-09 18:01:27.936: E/AndroidRuntime(16943): at com.heavyfork.sq.About.onCreate(About.java:27)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.Activity.performCreate(Activity.java:5154)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-09 18:01:27.936: E/AndroidRuntime(16943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2266)
05-09 18:01:27.936: E/AndroidRuntime(16943): ... 11 more
有任何想法吗?