Thursday, September 09, 2010

NoClassDefFoundError in BlackBerry

I have been struggling a few days with a strange error in BlackBerry. My app works fine in the emulator, but when you start it on BlackBerry Bold (software version 4.5) you get a NoClassDefFoundError. On BlackBerry Storm (software version 4.6) it works fine, but on Bold2 (version 5.0) again you get NoClassDefFoundError.

The documentation says:
Thrown if the Java Virtual Machine tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.


I have gone through all the changes since the last working version and I finally found it. I had added some fields like this:

fldPortHttp = new TextField("Port:", "", 20, Field.EDITABLE | BasicEditField.FILTER_NUMERIC);

This worked well, with no compilation errors and in the emulator, but caused the NoClassDefFoundError at runtime. The solution was simply to change to:

fldPortHttp = new BasicEditField("Port:", "", 20, Field.EDITABLE | BasicEditField.FILTER_NUMERIC);

Saturday, September 04, 2010

BlackBerry Java Application development

When I first started with BlackBerry development a few years ago it was difficult to find books on BlackBerry development. Since then interest has grown and today it is much easier to find good books on the subject.

I have just read one of the newer, BlackBerry Java Application Development: Beginner's Guide by Bill Foust. This is a useful book, even if you, like myself, is not a Beginner. It gives you a good overivew over the BlackBerry UI, which is probably what differs most from Java ME. It also has some material on more advanced subjects, like saving data and communicating over the network, which even though it uses the same classes and calls as standard Java ME is a bit more complicated.