1 Attachment(s)
error when switch activity in android
hai, i am new in android and android game is my first project. i am having problem with switching activity. my project contains 3 activities and 3 layout. there's no error in console but the application can't be run and the emulator says: "The Application TamaDroid (process tamagochi.app) has stopped unexpectedly. Please try again"
i am using android emulator 2.3 and API 9.
here is the code:
tamagochi.java
Code :
public class tamagochi extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tamagochi_layout);
Button loginButton = (Button) findViewById(R.id.login);
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), login.class);
startActivityForResult(myIntent, 0);
}
});
Button joinButton = (Button) findViewById(R.id.join);
joinButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), register.class);
startActivityForResult(myIntent, 0);
}
});
Button exitButton = (Button) findViewById(R.id.exit);
exitButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
System.exit(0);
}
});
}
}
AndroidManifest.xml
Code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tamagochi.app"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".tamagochi"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".choosepet"></activity>
<activity android:name=".login"></activity>
<activity android:name=".petMain"></activity>
<activity android:name=".register"></activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
and here is the screenshot of error:
Attachment 810
and here is the error in logcat
Quote:
10-24 11:41:08.006: ERROR/AndroidRuntime(644): FATAL EXCEPTION: main
10-24 11:41:08.006: ERROR/AndroidRuntime(644): java.lang.RuntimeException: Unable to start activity ComponentInfo{tamagochi.app/tamagochi.app.tamagochi}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1622)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1638)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread.access$1500(ActivityThr ead.java:117)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:928)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.os.Handler.dispatchMessage(Handler.java:99 )
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.os.Looper.loop(Looper.java:123)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread.main(ActivityThread.jav a:3647)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at java.lang.reflect.Method.invoke(Method.java:507)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:839)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:597)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at dalvik.system.NativeStart.main(Native Method)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ListActivity.onContentChanged(ListActi vity.java:243)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at com.android.internal.policy.impl.PhoneWindow.setCo ntentView(PhoneWindow.java:210)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.Activity.setContentView(Activity.java: 1657)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at tamagochi.app.tamagochi.onCreate(tamagochi.java:18 )
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1047)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1586)
10-24 11:41:08.006: ERROR/AndroidRuntime(644): ... 11 more
please help me, i am counting on your help. thank you..
Re: error when switch activity in android
Hello yefta,
Wow, that was a nice one trying to create games in Android (how I wish I could also create one). Anyways, I noticed on your LogCat, it says:
Quote:
10-24 11:41:08.006: ERROR/AndroidRuntime(644): java.lang.RuntimeException: Unable to start activity ComponentInfo{tamagochi.app/tamagochi.app.tamagochi}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
I think you need to open your list.xml in Design view then add a ListView component.
I hope that helps. God bless you.
Warm regards,
Mark Squall
Re: error when switch activity in android
thanks for the advice mark, but i've figured out the erors. i am using a button to change the layout and i don't need to use ListActivity, and one more fault is i cast the ImageButton to Button and that's very stupid fault.. LOL..
Thanks again mark.
Re: error when switch activity in android [SOLVED]
Hello yefta,
I am sorry if I did not solve your problem, but I am thankful because this thread will be of help to me and to others who might encounter the same problem.
Good luck to US in our Java programming in Android. :)
God bless to all javaprogrammingforums members and administrator.
Warm regards,
Mark Squall