ClickListener crashing Application

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

ClickListener crashing Application

Postby SMASH1337 » Wed Mar 16, 2011 1:14 am

I'm currently following a Sudoku tutorial from a book and there's something wrong with my code as it's force quitting on me and it's getting pretty frustrating to fix. Here's the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.SMASH.sudoku;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.Button;
  10. import android.view.Menu;
  11. import android.view.MenuInflater;
  12. import android.view.MenuItem;
  13.  
  14.  
  15.  
  16. public class Sudoku extends Activity{
  17.     /** Called when the activity is first created. */
  18.         public static final String TAG = "Sudoku";
  19.        
  20.     @Override
  21.     public void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.main);
  24.        
  25.         Log.d(TAG, "Before Button");
  26.        
  27.         OnClickListener  aboutListener = new OnClickListener(){
  28.                         @Override
  29.                         public void onClick(View view) {
  30.                                 Log.d(TAG, "Inside Click");
  31.                                 Intent i = new Intent(Sudoku.this, About.class);
  32.                                 startActivity(i);
  33.                         }
  34.                
  35.         };
  36.        
  37.         Log.d(TAG, "After Listener");
  38.        
  39.         Button aboutButton = (Button)findViewById(R.id.about_button);
  40.         Log.d(TAG, "After button Declaration");
  41.         aboutButton.setOnClickListener(aboutListener);
  42.        
  43.         Log.d(TAG, "Full loaded");
  44.     }
  45. }
  46.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


As you can see I used the Log to try and debug where and why the problem is happening, so here's the

03-15 19:01:31.059: INFO/ActivityManager(1256): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.SMASH.sudoku/.Sudoku }
03-15 19:01:31.090: DEBUG/AndroidRuntime(27304): Shutting down VM
03-15 19:01:31.106: DEBUG/jdwp(27304): Got wake-up signal, bailing out of select
03-15 19:01:31.106: DEBUG/dalvikvm(27304): Debugger has detached; object registry had 1 entries
03-15 19:01:31.122: INFO/ActivityManager(1256): Start proc com.SMASH.sudoku for activity com.SMASH.sudoku/.Sudoku: pid=27312 uid=10150 gids={}
03-15 19:01:31.137: INFO/AndroidRuntime(27304): NOTE: attach of thread 'Binder Thread #3' failed
03-15 19:01:31.137: ERROR/dalvikvm(27312): could not disable core file generation for pid 27312, errno=1
03-15 19:01:31.161: WARN/WidgetAidService(25823): BroadcastReceiver onReceive called
03-15 19:01:31.223: DEBUG/WidgetAidService(25823): ACTION_HOME_SCREEN_CHANGED - -1
03-15 19:01:31.231: DEBUG/dalvikvm(1156): GC_EXPLICIT freed 244 objects / 9480 bytes in 132ms
03-15 19:01:31.403: DEBUG/Sudoku(27312): Before Button
03-15 19:01:31.403: DEBUG/Sudoku(27312): After Listener
03-15 19:01:31.403: DEBUG/Sudoku(27312): After button Declaration
03-15 19:01:31.403: DEBUG/AndroidRuntime(27312): Shutting down VM
03-15 19:01:31.411: WARN/dalvikvm(27312): threadid=1: thread exiting with uncaught exception (group=0x400208b0)
03-15 19:01:31.419: DEBUG/dalvikvm(1156): GC_EXPLICIT freed 2 objects / 48 bytes in 151ms
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): FATAL EXCEPTION: main
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.SMASH.sudoku/com.SMASH.sudoku.Sudoku}: java.lang.NullPointerException
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread.access$2500(ActivityThread.java:129)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.os.Looper.loop(Looper.java:143)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread.main(ActivityThread.java:4701)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at java.lang.reflect.Method.invoke(Method.java:521)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at dalvik.system.NativeStart.main(Native Method)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): Caused by: java.lang.NullPointerException
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at com.SMASH.sudoku.Sudoku.onCreate(Sudoku.java:41)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
03-15 19:01:31.419: ERROR/AndroidRuntime(27312): ... 11 more
03-15 19:01:31.434: WARN/ActivityManager(1256): Force finishing activity com.SMASH.sudoku/.Sudoku
03-15 19:01:31.567: DEBUG/dalvikvm(1156): GC_EXPLICIT freed 2 objects / 64 bytes in 144ms

As you can see the problem is setting the onClickListener... but everything looks fine. It's stuff like this that's making it really hard for me to progress in my knowledge of Android development... should be simple stuff.
SMASH1337
Freshman
Freshman
 
Posts: 9
Joined: Wed Mar 16, 2011 1:03 am

Top

Re: ClickListener crashing Application

Postby SMASH1337 » Wed Mar 16, 2011 1:44 am

So I fixed it. I just removed an extra activity that I hadn't implemented out of the Manifest, then reran it, and it worked... weird thing is I put that extra activity back in and it still worked... makes no stinking sense, but I guess now I know what to do when I get an unexplainable error: fiddle with the Manifest.
SMASH1337
Freshman
Freshman
 
Posts: 9
Joined: Wed Mar 16, 2011 1:03 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests