Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: error when switch activity in android

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    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

    <?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:

    error.android.JPG

    and here is the error in logcat

    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..
    Last edited by yefta; October 23rd, 2011 at 11:47 PM.


  2. #2
    Junior Member marksquall's Avatar
    Join Date
    Jan 2009
    Posts
    27
    My Mood
    Fine
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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:


    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

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Junior Member marksquall's Avatar
    Join Date
    Jan 2009
    Posts
    27
    My Mood
    Fine
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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

Similar Threads

  1. Android Development
    By bgroenks96 in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: August 30th, 2013, 10:03 PM
  2. What is the best SDK for creating new Android applications?
    By p0oint in forum Android Development
    Replies: 7
    Last Post: May 2nd, 2013, 02:02 PM
  3. How to use Android in (Eclipse || NetBeans)
    By benglish in forum Android Development
    Replies: 2
    Last Post: October 21st, 2011, 06:28 AM
  4. Android Threading api (for bluetooth).
    By new_hope in forum Threads
    Replies: 1
    Last Post: October 1st, 2011, 08:10 AM
  5. [SOLVED] Medication of ArrayDemo.java to include iterative menu
    By xyldon27 in forum Loops & Control Statements
    Replies: 8
    Last Post: June 30th, 2009, 02:10 AM