Android Tutorial

(avery) #1
Android Tutorial 65

In your project, edit the file MyFirstAndroidApp.java and create a
new method called forceError() in your class and make a call to this
method in your onCreate() method.

The forceError() method forces a new unhandled error in your
application.

The forceError() method should look something like this:

public void forceError() {
if(true) {
throw new Error(“Whoops”);
}
}


It’s probably helpful at this point to run the application and watch
what happens. Do this using the Run Configuration first. In the
emulator, you see that the application has stopped unexpectedly.
You are prompted by a dialog that enables you to forcefully close
the application, as shown in Figure.

Shut down the application and the emulator. Now it’s time to
debug. You can debug the MyFirstAndroidApp application using the
following steps:


  1. Choose the Debug As icon drop-down menu on the toolbar (the little green
    bug with the drop-down arrow).

  2. Pull the drop-down menu and choose the Debug Configuration you
    created. (If you do not see it listed, choose the Debug Configurations...
    item and select the appropriate configuration. The Debug Configuration
    shows up on this drop-down list the next time you run the configuration.)

  3. Continue as you did with the Run Configuration and choose the
    appropriate AVD and launch the emulator again, unlocking it if needed.

Free download pdf