1

I am new developer of BlackBerry apps. I have found a runtime error in a program. But I am not sure which type of error in the program has occurred. I have no idea how to see an error in a BlackBerry app.

I am working in Eclipse Helios.

How to see runtime errors in BlackBerry programs?

Nate
  • 31,017
  • 13
  • 83
  • 207

1 Answers1

0

In Eclipse, you can debug your application, either by connecting a real BlackBerry device via the USB cable, or you can download a BlackBerry simulator and use it to test your app. Note that BlackBerry simulators only are supported on Windows.

Once you start debugging, you should see the Eclipse Debug perspective. Normally, one of the open windows in Eclipse will be the Console window. If you don't see that, use the Eclipse menu:

Window -> Show View -> Console

While your app runs (or your device is connected), you should see output in the Console window like this:

[0.0] JVM: bklt[1]: setTimeout 120
[0.0] JVM: bklt[1] @438007: JBSC on=0
[0.0] JVM: bklt[1] @438007: SC 0
[0.0] JVM: bklt[1]: setTimeout 120
[0.0] VM:TRJFp=net_rim_services_impl
[0.0] net_rim_crypto_1-3(4CC8AA32)
[0.0]  StatusClean

Any standard output that your program creates (e.g. System.out.println()) will be mixed in with these messages from the OS.

Normal java.lang.Exception objects in BlackBerry have much of the useful information removed, so if you don't know what kind of exception is being thrown, or where, you can choose to debug the problem by simply catching all java.lang.Throwable objects in your app's main program:

public static void main(String[] args) {
    try {
        Application app = new MyApp();
        app.enterEventDispatcher();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

public MyApp() {            

    ButtonScreen bs = new ButtonScreen();
    pushScreen(bs);

    bs.throwException();  // <- for test purposes!
}

Then, you'll see something like this in your Console window and can find out what's going wrong in your code:

[0.0] FocusHistory: Focus gained; App HelloBB; Component mypackage.ButtonScreen$1
[0.0] IllegalArgumentException
[0.0] testing exception handling code!
[0.0] HelloBB(51B3A691)
[0.0]  ButtonScreen
[0.0]  throwException
[0.0]  0x74C
[0.0] HelloBB(51B3A691)
[0.0]  MyApp
[0.0]  <init>
[0.0]  0x151B
[0.0] HelloBB(51B3A691)
[0.0]  MyApp
[0.0]  main
[0.0]  0x14B2
[0.0] VM:TRJFp=HelloBB
[0.0] net_rim_cldc-26(4CC89E31)
[0.0]  BlockingTimeSource
[0.0]  run
[0.0]  0x104D
[0.0] VM:TRJFp=HelloBB
[0.0] net_rim_cldc-26(4CC89E31)
[0.0]  BlockingTimeSource
[0.0]  run
[0.0]  0x104D
[0.0] VM:TRJFp=HelloBB
[0.0] net_rim_cldc-26(4CC89E31)
[0.0]  BlockingTimeSource
[0.0]  run
[0.0]  0x104D

in this situation, I put this code:

public void throwException() throws Exception {
    throw new IllegalArgumentException("testing exception handling code!");
}

into my app, so that my MyApp#main() method called the MyApp constructor, which called the ButtonScreen#throwException() method.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • sir i an try these but console only show a success message every time and another thing is that i am using system.out.println("Hello Message"); it can not appear at console – Rahul Vijayvargiya Jun 11 '13 at 03:56
  • @Rahul, If you choose to **Debug** your application on the device, it will show any `System.out.println()` messages in the Console window, and it will show the output of the `Throwable#printStackTrace()` as I showed. Remember that the Console **also** shows lots of messages from the operating system, so you need to look through the output carefully, so that you don't miss the messages from your application. But, they are there. – Nate Jun 11 '13 at 04:48
  • @Rahul, you can also see [this similar question](http://stackoverflow.com/q/5612034/119114) for two more ways to log information from a BlackBerry application. – Nate Jun 11 '13 at 04:51