Android App ForceCloses about starting a new action
I'm new to Android development and I'm having trouble with Force Close on new Android Activity Pages.
My structure looks like this:
Home -> Menu page (works great) -> New game screen (force closure)
Activity call:
public void btnNewGame_Click(View view)
{
Intent i = new Intent(this, NewGameScreen.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
manifesto
<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);
Errors:
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
source to share
The answer is very simple, you just forgot to insert the NewGameScreen activity record in AndroidManiFest.xml Write the following line in AndroidManifest.xml file before the tag.
<activity android:name=".NewGameScreen"></activity>
And also important is that your NewGameScreen class should extends
Activity
source to share
You need to specify the id of your ListView as android:id="@android:id/list"
if you are extending LIstActivity. Then you can get the ListView handler from getLIstView (); If you are extending the Activity, you can specify any other ID in the ListView and get it using findViewbyId () From the LOgCat trace, it looks like you are using ListActivity.
source to share