02 Aug 2013, 00:10
Generic-user-small

atibur rahman (5 posts)

Hey i’m trying to add an activity. page 61

i did this. but when i ran my application my emulator give s me error massage. the massage is "Sorry the application Sudoku (process org.example.Sudoku ) has stopped unexpectedly. please try again". I can not find any mistake. What should i do now?
02 Aug 2013, 11:25
Generic-user-small

Anthony Shaw (135 posts)

Look in the logcat, it should tell you what caused the problem and the line numbers and source code module names where the problem occurred. If it is not immediatly obvious to you what is going wrong post the section of the logcat that describes the error and I will have a look at it

02 Aug 2013, 19:59
Generic-user-small

atibur rahman (5 posts)

here is the logcat entry.

08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.os.Handler.dispatchMessage(Handler.java:99) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.os.Looper.loop(Looper.java:123) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.ActivityThread.main(ActivityThread.java:4627) 08-03 02:55:46.423: E/AndroidRuntime(279): at java.lang.reflect.Method.invokeNative(Native Method) 08-03 02:55:46.423: E/AndroidRuntime(279): at java.lang.reflect.Method.invoke(Method.java:521) 08-03 02:55:46.423: E/AndroidRuntime(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 08-03 02:55:46.423: E/AndroidRuntime(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 08-03 02:55:46.423: E/AndroidRuntime(279): at dalvik.system.NativeStart.main(Native Method) 08-03 02:55:46.423: E/AndroidRuntime(279): Caused by: java.lang.NullPointerException 08-03 02:55:46.423: E/AndroidRuntime(279): at org.example.sudoku.Sudoku.onCreate(Sudoku.java:20) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-03 02:55:46.423: E/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 08-03 02:55:46.423: E/AndroidRuntime(279): … 11 more 08-03 02:55:46.464: W/ActivityManager(59): Force finishing activity org.example.sudoku/.Sudoku 08-03 02:55:46.994: W/ActivityManager(59): Activity pause timeout for HistoryRecord{43ec1560 org.example.sudoku/.Sudoku} 08-03 02:55:47.014: I/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 26628 ms (total 26628 ms) 08-03 02:55:57.310: W/ActivityManager(59): Activity destroy timeout for HistoryRecord{43ec1560 org.example.sudoku/.Sudoku}

03 Aug 2013, 08:38
Generic-user-small

Anthony Shaw (135 posts)

Did you remember to add the activity to the manifest?

03 Aug 2013, 09:49
Generic-user-small

atibur rahman (5 posts)

yes i add the activity ti the manifest.

        android:name="org.example.sudoku.About"
        android:label="@string/about_title">

can you check it.

08-03 02:55:46.423: E/AndroidRuntime(279): Caused by: java.lang.NullPointerException

08-03 02:55:46.423: E/AndroidRuntime(279): at org.example.sudoku.Sudoku.onCreate(Sudoku.java:20)

but i can not find any problem. i did as it is in the book. please help me.

03 Aug 2013, 09:54
Generic-user-small

atibur rahman (5 posts)

here is the on crete function from sudoku class.

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Set up click listeners for all the buttons View continueButton = findViewById(R.id.continue_button); continueButton.setOnClickListener((OnClickListener) this); View newButton = findViewById(R.id.new_button); newButton.setOnClickListener((OnClickListener) this); View aboutButton = findViewById(R.id.about_button); aboutButton.setOnClickListener((OnClickListener) this); View exitButton = findViewById(R.id.exit_button); exitButton.setOnClickListener((OnClickListener) this); }

03 Aug 2013, 11:28
Generic-user-small

Anthony Shaw (135 posts)

The problem is happening at line 20 of Sudoku.java, but from the code you posted I cannot tell which bit is line 20. I can guess that it is one of the lines where setOnClickListener is being called but the real problem is that the line before that is not finding the button and the findViewById is returning null. Double check that the button involved is actually in the layout and if it appears to be there try do a Project->Clean and running it again.

28 Sep 2013, 10:44
Generic-user-small

Fernando Arredondo (1 post)

Chicos, aqui teneis el codigo sin errores

package org.example.sudokuv1;

import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;

public class Sudoku extends Activity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_sudoku);
	
	View newButton = findViewById(R.id.new_button);
	newButton.setOnClickListener(this); 
	
	
	View continueButton = findViewById(R.id.continue_button);
	continueButton.setOnClickListener(this); 
	
	View aboutButton = findViewById(R.id.about_button);
	aboutButton.setOnClickListener(this);
	
	View exitButton = findViewById(R.id.exit_button);
	exitButton.setOnClickListener(this);
}
	
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.about_button:
			Intent i = new Intent(this,About.class);
			startActivity(i);
		break;
		}
	}
			
	

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.sudoku, menu);
	return true;
}

}

  You must be logged in to comment