Debugging with Log Messages

The Log class provides several static methods to print messages of various severity levels to the Android system log:

5. Since Android 2.2.

LogCat î^ B Console-) ® ® © © © I + if _ I 181 ^ =

LogCat î^ B Console-) ® ® © © © I + if _ I 181 ^ =

Time

pid

tag

Message

06

-08

02

18 . .

D

2415

à n d r u l d R u n 11 m e

Shutting down VM

06

-08

02

18 . .

D

2415

dalvikvm

Debugger has detached;

object registry

06

-08

02

18 . .

I

2415

AndroidRuntime

NOTE: attach of thread

1 Binder Thread

06

-08

02

18 . .

D

2431

AndroidRuntime

>>>>>>>>>>>>>> AndroidRuntime START <<

06

-08

02

18 . .

D

2431

AndroidRuntime

CheckJNI is ON

06

-08

02

18 . .

D

2431

AndroidRuntime

--- registering native

functions ---

06

-08

02

18 . .

D

2431

AndroidRuntime

Shutting down VM

06

-08

02

18 . .

D

2431

dalvikvm

Debugger has detached;

object registry

06

-08

02

18 . .

I

2431

AndroidRuntime

NOTE: attach of thread

1 Binder Thread

< L

rrr

-1

Filter

Figure 3.13: Debugging output in the LogCat view

Users will never see this log, but as a developer you can view it in a couple ways. In Eclipse, open the LogCat view by selecting Window > Show View > Other... > Android > LogCat (see Figure 3.13). The view can be filtered by severity or by the tag you specified on the method call.

If you're not using Eclipse, you can see the same output by running the adb logcat command.6 I recommend you start this command in a separate window and leave it running all the time that the emulator is running. It won't interfere with any other monitors.

I can't stress enough how useful the Android log will be during development. Remember that error we saw earlier with the About box (Figure 3.7, on page 61)? If you had opened the LogCat view at that point, you would have seen this message: "ActivityNotFoundException: Unable to find explicit activity class...have you declared this activity in your AndroidManifest.xml?" It doesn't get any plainer than that.

6. http://d.android.com/guide/developing/tools/adb.html

0 0

Post a comment