0

我是 android 开发新手,在新的 Android 活动页面上遇到强制关闭问题。

我的结构是这样的:

主页 -> 菜单页面(工作正常) -> 新游戏屏幕(强制关闭)

调用活动:

    public void btnNewGame_Click(View view)
{
    Intent i = new Intent(this, NewGameScreen.class);
    startActivityForResult(i, ACTIVITY_CREATE);
}

显现

        <activity  android:name=".NewGameScreen"
                android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >



    <ExpandableListView
        android:id="@+id/eLVGameList"
        android:layout_width="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight=".75"
        android:background="@null" android:layout_height="0dip">

    </ExpandableListView>

</LinearLayout>

NewGameScreenActivity

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loadgame);


   ExpandableListView epView = (ExpandableListView) findViewById(R.id.eLVGameList);
   ExpandableListAdapter mAdapter = new GameListAdapter();
   epView.setAdapter(mAdapter);

错误:

03-05 20:16:57.375: E/AndroidRuntime(887): FATAL EXCEPTION: main
03-05 20:16:57.375: E/AndroidRuntime(887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.NewGameScreen}: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.os.Looper.loop(Looper.java:137)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 20:16:57.375: E/AndroidRuntime(887):  at java.lang.reflect.Method.invokeNative(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887):  at java.lang.reflect.Method.invoke(Method.java:511)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 20:16:57.375: E/AndroidRuntime(887):  at dalvik.system.NativeStart.main(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887): Caused by: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ExpandableListActivity.onContentChanged(ExpandableListActivity.java:222)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Activity.setContentView(Activity.java:1835)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.example.helloandroid.NewGameScreen.onCreate(NewGameScreen.java:22)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Activity.performCreate(Activity.java:4465)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 20:16:57.375: E/AndroidRuntime(887):  ... 11 more
4

3 回答 3

3

用这个改变你的 ExpandableListView id

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

如果您的课程扩展了 Activity 则将其更改为

public class className extends ListActivity

你可以通过调用方法来获取你的 ExpandableListView

ExpandableListView listView = getListView();
于 2012-03-06T04:36:08.710 回答
0

答案很简单,您只是忘记在 AndroidManiFest.xml 中插入 NewGameScreen Activity 的 Entry 在您的 AndroidManifest.xml 文件中标记之前写下以下行。

<activity android:name=".NewGameScreen"></activity>

还有你的 NewGameScreen 类必须的重要的事情extends Activity

于 2012-03-06T04:37:36.100 回答
0

android:id="@android:id/list"如果要扩展 LIstActivity,则需要将 ListView 的 id 指定为 。然后您可以从 getLIstView(); 获取您的 ListView 处理程序;如果您正在扩展 Activity,那么您可以为您的 ListView 提供任何其他 id 并使用 findViewbyId() 从 LOgCat 跟踪中获取它,看起来您正在使用 ListActivity。

于 2012-03-06T05:06:06.833 回答