Catching java.lang.Error
I'm developing a Javame framework for J2me and Blackberry. I read the type(bb or j2me) from the device, and then I load the right classes depending on the detected device.
Only I get a java.lang.error when executing the following code. I think that's because I use a blackberry package in the KuixCanvasBB that j2me doesn't support. But is there a way to catch this error?
KuixCanvas canvas;
if(Settings.j2me) {
System.out.println("j2me");
canvas = new KuixCanvasJ2me(this, isFullscreen());
}
else {
System.out.println("BB");
try {
canvas = new KuixCanvasBB(this, isFullscreen());
//canvas = new KuixCanvasJ2me(this, isFullscreen());
}
catch (java.lang.Error e) {
canvas=null;
}
}
I still get an Error when executing the above code:
java.lang.Error: ClassFormatError: 154
- java.lang.Class.invoke_verify(), bci=0
- java.lang.Class.initialize(), bci=117
- java.lang.Class.initialize(), bci=139
开发者_如何学运维 - java.lang.Class.forName(), bci=0
Can I catch this error without the app shutting down?
Since many J2ME VMs will verify all code before running anything such code could easily be rejected from even installing on many devices.
A safer solution would probably be to make this a build-time decision, since you'll need separate .jar
files for the final build anyway.
The reason you get the error is probably because references to other classes get resolved as soon as the method is entered on the JVM.
精彩评论