C H A P T E R  14


Adding logging statements into your code is the simplest debugging method. The logging framework allows you to log into storage (RMS) or your file system at runtime without changing your binary. There are four debugging levels to help you better monitor your code: DEBUG, INFO, WARNING and ERROR.

Default and the lowest level.Third level
Second levelHighest level debugging

You should use the Log class coupled with NetBeans preprocessing tags to reduce its overhead completely in runtime. For information on the Log class, see com.sun.lwuit.util.Log in the LWUIT API documentation.

14.1 Writing to a Log

To write into a log, you use the static p(String text) or p(String text, int level) methods. For example:

Log.p(“Finish loading images”).

14.2 Showing the Log

To print out the log, use the static showLog() method. If you are using microedition.io.file.FileConnection, the log is written to the root location as the file file.log. If you don't use a file connection, a new Form appears with the log text inside.

The following example shows how to work with NetBeans preprocessing tags:

// In case you are in debug mode, import Log class
// #debug
import com.sun.lwuit.util.Log;

// Here is how to surround a log method, inside your code
// #mdebug

if(keyCode == Canvas.KEY_POUND) {

Using preprocessing tags reduces the size of the source code, which is an important issue in mobile development. For more information, please refer to NetBeans information on preprocessing tags.