Debug Your Project

The Android Plugin for Eclipse also has excellent integration with the Eclipse debugger. To demonstrate this, introduce a bug into your code. Change your HelloAndroid source code to look like this:


import; import android.os.Bundle;

public class HelloAndroid extends Activity {

/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Object o = null; o.toString();


This change simply introduces a NullPointerException into your code. If you run your application again, you'l eventually see this:

Press "Force Quit" to terminate the application and close the emulator window.

To find out more about the error, set a breakpoint in your source code on the line Object o = null; (doubleclick on the marker bar next to the source code line). Then select Run > Debug History > Hello, Android from the menu to enter debug mode. Your app will restart in the emulator, but this time it will suspend when it reaches the breakpoint you set. You can then step through the code in Eclipse's Debug Perspective, just as you would for any other application.

0 0

Post a comment