button crashes app/\end activity via menu

Put your problem here if it does not fit any of the other categories.

button crashes app/\end activity via menu

Postby superferd » Sun May 15, 2011 8:50 am

So, i am new here(hi everyone!) and new to java/android developing. I have done a few tutorials and spend a lot of time reading documentation. I have also looked extensively through the API demos and found a specific thing i needed. The forwarding from one activity to the next on the click of a button. It just won't work. So here are my main activity and manifest files. Please take a quick look or help me debug.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.ferdix.wham;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.Menu;
  7. import android.view.MenuInflater;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11.  
  12. public class Start extends Activity {
  13.     public boolean onCreateOptionsMenu(Menu menu) {
  14.         MenuInflater inflater = getMenuInflater();
  15.         inflater.inflate(R.menu.menumain, menu);
  16.         return true; }
  17.  
  18.         protected void onCreate(Bundle savedInstanceState)
  19.     {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.main);
  22.  
  23.         Button goButton = (Button)findViewById(R.id.new_game);
  24.         goButton.setOnClickListener(mGoListener);
  25.         Button goButton1 = (Button)findViewById(R.id.imageButton1);
  26.         goButton1.setOnClickListener(mGoListener);
  27.     }
  28.  
  29.     private OnClickListener mGoListener = new OnClickListener()
  30.     {
  31.         public void onClick(View v)
  32.         {
  33.             Intent intent = new Intent();
  34.             intent.setClass(Start.this, game.class);
  35.             startActivity(intent);
  36.             finish();
  37.         }
  38.     };
  39. }
  40.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


manifest
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="com.ferdix.wham"
  4.      android:versionCode="1"
  5.      android:versionName="1.0" android:installLocation="auto" android:sharedUserLabel="@string/wham">
  6.     <uses-sdk android:minSdkVersion="8" />
  7.     <application android:icon="@drawable/icon" android:label="Whack-A-Mole!">
  8.         <activity android:label="WhackAMole!" android:name=".Start">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.MAIN" />
  11.                 <category android:name="android.intent.category.DEFAULT"></category>
  12.                 <category android:name="android.intent.category.LAUNCHER" />
  13.                
  14.             </intent-filter>
  15.         </activity>
  16.         <activity android:label="game" android:name=".game">
  17.             <intent-filter>
  18.                 <action android:name="android.intent.action.MAIN"></action>
  19.                 <category android:name="android.intent.catergory.DEFAULT"></category>
  20.             </intent-filter>
  21.         </activity>
  22.         </application>
  23. </manifest>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4



Thanks in advance!
Last edited by superferd on Sat May 21, 2011 11:55 pm, edited 3 times in total.
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Top

Re: The problem is i don't know where the problem is

Postby superferd » Sun May 15, 2011 9:33 am

I don't know where to look and for what in the logcat output. Please take a look.

Syntax: [ Download ] [ Hide ]
  1. 05-15 10:31:16.645: INFO/ActivityManager(66): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ferdix.wham/.Start bnds=[5,414][115,532] } 
  2. 05-15 10:31:17.765: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{45019638 com.android.launcher/com.android.launcher2.Launcher} 
  3. 05-15 10:31:18.245: INFO/ActivityManager(66): Start proc com.ferdix.wham for activity com.ferdix.wham/.Start: pid=556 uid=10036 gids={} 
  4. 05-15 10:31:19.406: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol 
  5. 05-15 10:31:24.235: DEBUG/dalvikvm(556): GC_EXTERNAL_ALLOC freed 767 objects / 55960 bytes in 267ms 
  6. 05-15 10:31:26.066: DEBUG/AndroidRuntime(556): Shutting down VM 
  7. 05-15 10:31:26.075: WARN/dalvikvm(556): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
  8. 05-15 10:31:26.446: ERROR/AndroidRuntime(556): FATAL EXCEPTION: main 
  9. 05-15 10:31:26.446: ERROR/AndroidRuntime(556): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ferdix.wham/com.ferdix.wham.Start}: java.lang.NullPointerException 
  10. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
  11. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
  12. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
  13. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
  14. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.os.Handler.dispatchMessage(Handler.java:99) 
  15. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.os.Looper.loop(Looper.java:123) 
  16. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread.main(ActivityThread.java:4627) 
  17. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at java.lang.reflect.Method.invokeNative(Native Method) 
  18. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at java.lang.reflect.Method.invoke(Method.java:521) 
  19. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
  20. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
  21. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at dalvik.system.NativeStart.main(Native Method) 
  22. 05-15 10:31:26.446: ERROR/AndroidRuntime(556): Caused by: java.lang.NullPointerException 
  23. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at com.ferdix.wham.Start.onCreate(Start.java:20) 
  24. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
  25. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
  26. 05-15 10:31:26.446: ERROR/AndroidRuntime(556):   ... 11 more 
  27. 05-15 10:31:27.085: WARN/ActivityManager(66):  Force finishing activity com.ferdix.wham/.Start 
  28. 05-15 10:31:28.546: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{4505dc98 com.ferdix.wham/.Start} 
  29. 05-15 10:31:31.326: INFO/ActivityManager(66): Process com.android.music (pid 283) has died. 
  30. 05-15 10:31:33.386: WARN/ActivityManager(66): Activity idle timeout for HistoryRecord{4505dc98 com.ferdix.wham/.Start} 
  31. 05-15 10:31:36.995: WARN/ActivityManager(66): Launch timeout has expired, giving up wake lock! 
  32. 05-15 10:31:38.725: WARN/ActivityManager(66): Activity idle timeout for HistoryRecord{45019638 com.android.launcher/com.android.launcher2.Launcher} 
  33. 05-15 10:31:43.879: WARN/ActivityManager(66): Activity destroy timeout for HistoryRecord{4505dc98 com.ferdix.wham/.Start} 
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby imbroken » Sun May 15, 2011 6:00 pm

try to remove the finish in your onclicklistener.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: using logcat to debug?

Postby superferd » Sun May 15, 2011 7:19 pm

I tried that but unfortunately it didn't help. Here is a new logcat output:
Code: Select all
05-15 20:13:11.771: DEBUG/AndroidRuntime(377): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-15 20:13:11.771: DEBUG/AndroidRuntime(377): CheckJNI is ON
05-15 20:13:12.841: DEBUG/AndroidRuntime(377): --- registering native functions ---
05-15 20:13:16.421: INFO/ActivityManager(66): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.ferdix.wham/.Start }
05-15 20:13:16.761: DEBUG/AndroidRuntime(377): Shutting down VM
05-15 20:13:16.846: DEBUG/dalvikvm(377): Debugger has detached; object registry had 1 entries
05-15 20:13:17.921: INFO/ActivityManager(66): Start proc com.ferdix.wham for activity com.ferdix.wham/.Start: pid=384 uid=10036 gids={}
05-15 20:13:18.971: DEBUG/dalvikvm(33): GC_EXPLICIT freed 263 objects / 10064 bytes in 909ms
05-15 20:13:19.183: DEBUG/dalvikvm(170): GC_EXPLICIT freed 174 objects / 12504 bytes in 5809ms
05-15 20:13:20.391: DEBUG/dalvikvm(33): GC_EXPLICIT freed 27 objects / 1160 bytes in 1136ms
05-15 20:13:20.921: DEBUG/dalvikvm(33): GC_EXPLICIT freed 2 objects / 64 bytes in 532ms
05-15 20:13:22.630: DEBUG/dalvikvm(384): GC_EXTERNAL_ALLOC freed 847 objects / 58960 bytes in 215ms
05-15 20:13:24.421: DEBUG/AndroidRuntime(384): Shutting down VM
05-15 20:13:24.421: WARN/dalvikvm(384): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-15 20:13:24.601: ERROR/AndroidRuntime(384): FATAL EXCEPTION: main
05-15 20:13:24.601: ERROR/AndroidRuntime(384): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ferdix.wham/com.ferdix.wham.Start}: java.lang.NullPointerException
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.os.Looper.loop(Looper.java:123)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at java.lang.reflect.Method.invokeNative(Native Method)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at java.lang.reflect.Method.invoke(Method.java:521)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at dalvik.system.NativeStart.main(Native Method)
05-15 20:13:24.601: ERROR/AndroidRuntime(384): Caused by: java.lang.NullPointerException
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at com.ferdix.wham.Start.onCreate(Start.java:20)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-15 20:13:24.601: ERROR/AndroidRuntime(384):     ... 11 more
05-15 20:13:24.782: WARN/ActivityManager(66):   Force finishing activity com.ferdix.wham/.Start
05-15 20:13:25.680: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{44f96058 com.ferdix.wham/.Start}
05-15 20:13:27.953: WARN/ActivityManager(66): Launch timeout has expired, giving up wake lock!
05-15 20:13:36.152: DEBUG/dalvikvm(275): GC_EXPLICIT freed 31 objects / 1424 bytes in 206ms
05-15 20:13:40.922: WARN/ActivityManager(66): Activity destroy timeout for HistoryRecord{44f96058 com.ferdix.wham/.Start}
05-15 20:15:03.610: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol


I highlited what i think causes the error but i really have no idea, EDIT: aha can't highlite in code tags
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby imbroken » Mon May 16, 2011 7:17 am

The exception occurs in onCreate, try to comment out the four statements for the buttons and see if it runs.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: using logcat to debug?

Postby superferd » Mon May 16, 2011 5:37 pm

I don't think i understand you? I am sorry my english is not the best.
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Top

Re: using logcat to debug?

Postby superferd » Mon May 16, 2011 7:02 pm

Ah yes, I figured it out. I think...

I have removed the 4 lines of button code and now it will start the app. But how do I make the buttons work?
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby imbroken » Mon May 16, 2011 9:24 pm

Can you post your R.layout.main?

Maybe I'm blind, but i can't see an error
Shame on me, can't go to work tomorrow :)
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: using logcat to debug?

Postby superferd » Mon May 16, 2011 9:56 pm

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="fill_parent"
  4.    android:layout_height="fill_parent"
  5.    android:orientation="vertical"  
  6.    android:background="@drawable/background">
  7.         <TextView android:id="@+id/textViewhighscore"
  8.         android:layout_width="wrap_content"
  9.         android:layout_height="wrap_content"
  10.         android:textSize="35dp"
  11.         android:text="@string/highscoretext"></TextView>
  12.     <ImageButton android:id="@+id/imageButton1"
  13.         android:src="@drawable/playportrait"
  14.         android:layout_width="wrap_content"
  15.         android:layout_height="wrap_content"
  16.         android:layout_gravity="center|bottom"
  17.         android:layout_alignParentBottom="true"
  18.         android:layout_centerHorizontal="true">
  19.         <requestFocus /></ImageButton>
  20.     <TextView android:layout_width="wrap_content"
  21.         android:layout_alignParentRight="true"
  22.         android:layout_height="wrap_content"
  23.         android:text="@string/score"
  24.         android:textSize="35dp"  
  25.         android:id="@+id/score"></TextView>
  26. </RelativeLayout>
  27.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


Here you go! Thanks for the help!
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby imbroken » Tue May 17, 2011 6:44 am

There is only one button in your layout file, imageButton1. There is now new_game button. Define the new_game button in your layout.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: using logcat to debug?

Postby superferd » Tue May 17, 2011 8:51 am

The new_game button is in a optionsmenu, I don't have it here. Will post the .xml when I get home.
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby wakawaka » Tue May 17, 2011 10:47 am

Ooops... There is problem is button code.
Android Development Tutorials and Code Snippets: http://forum.gssdaily.com/
wakawaka
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Tue Jan 11, 2011 1:51 pm

Re: using logcat to debug?

Postby superferd » Tue May 17, 2011 10:58 am

Ok, any way to make it work?
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Re: using logcat to debug?

Postby imbroken » Tue May 17, 2011 11:40 am

You can't use buttons from the options menu like this. you have to do this in onCreateOptionsmenu and onMenuItemselected (not 100% sure about the names, but somethink like this).
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: using logcat to debug?

Postby superferd » Tue May 17, 2011 2:56 pm

ok will try something :)
-superferd-please help me
Die? over my dead body!
superferd
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun May 15, 2011 8:23 am

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests