Donnerstag, 26. November 2009

Praise the EventLog

I am developing BlackBerry applications with pure Eclipse without RIM's eJDE. I hope at some point in the future the plugin will be better but currently I can use libraries and unit testing much better without.
But this also can get you into lot of troubles: when building against a normal JRE it can happen that methods will be used that are not available on the device. This is because the rapc compiler does not check jar-files as strictly as source files. There is the preverification process for jar files. I can detect illegal classes but if a normal class uses methods of a system class let's say from i.e. java.lang.String which are not available in ME (a good example ist "split") this will not cause any errors. And this could cause you a lot of headaches.

So today I found myself in a situation where my application did not start on the BlackBerry simulator. It was an auto start library but it looked as it was never started.

1st look is normally into the eventlog!
(tip: simulator a connected USB cable via the simulator app menu and download it directly with javaloader, much better for reading and searching).

It shows me multiple entries of:
app:System data:Linker error: 'VerifyError' for MyModuleX
This normally can be translated as: you are using something which is not allowed!
I can also see the complete loading procedure of my module if I look more closer and so I found the detail I wanted to know:
System data:VM:LINK MyModuleX
System data:VM:UNDF de.preusslerpark.mytest.MyClass
System data:Symbol 'Vector.get' not found.
This tells me exactly what I want to know: the class MyClass uses Vector.get which in unknown in CLDC environments (UNDeFined). It wasn't even my code (and the developer was not in the office today). But I found the source and replaced the call with elementAt. Next tip: search for every occurence of this call (great that "open call hierarchy" works on every method call and not only method declararions). Normally there are more then one and you don't want to find yourself in the same position once more after building multiple libraries, your app and the simulator boot process.

Sometimes I did not see the exact class where the problem layed and in very few cases it did not tell me at all which method was used.

But look into the eventlog and look closely, most of the time you will find the problems there!

And maybe someday someone should write a better preverify.exe ;-)

Keine Kommentare:

Kommentar veröffentlichen