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アクティビティのエントリを挿入するのを忘れただけです。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 に答える