Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
peterhansen
Posts: 4
Registered: ‎05-11-2009
My Device: Not Specified

Problems when compiling application with JDE 4.2 or lower

Greetings everyone,

 

   I'm having this serious problem for some time and still haven't figured out how to solve it. I've developed 2 J2ME applications that works fine on BlackBerry devices with JDE 4.5 or higher (tested on two 8310 and one 8100 devices). I'm using Netbeans 6.5 to compile the project and I'm manually generating COD files with rapc.

 

   The problem happens when I try to run the apps in devices with software versions older than 4.5:

 

  • if I try to convert jar->cod with rapc 4.6 and net_rim_api 4.6, I get Veryfication Error at offset xxxx.yyyy (the number changes). This is actually expected, since the compiler JDE is newer than device's. This code runs fine on 4.5+ phones though;
  • using rapc 4.6 and net_rim_api 4.2 : as odd as it may seems, this is so far the only way I managed to make the apps run on a 8310 4.2.2 . Trying to install on a 8100 4.2.0 or on a 8700 4.1.0 generates errors such as "invalid cod file" and "Error: file is not a valid Java code file", depending on the install method (tried OTA, javaloader and DesktopManager);
  • using rapc 4.2 and net_rim_api 4.2 / rapc 4.1 and net_rim_api 4.1: this should be the correct way to do it, but even though there are no compilation errors, the apps don't work on ANY device. I receive a "Uncaught Exception: noclassdeffounderror"at runtime, with no more specific messages.


   I'm not using any restricted APIs and the code is not signed. Just a bare minimum of BlackBerry's API is used, mostly for event handling: net.rim.device.api.system.Application, net.rim.device.api.ui.Keypad and net.rim.device.api.ui.UiApplication .

 

   The closest I've got to make this work was doing the following:

 

  • wrote a "hello world" app. It worked even on 4.2 phones, so there must be something in my code that generates the "noclassdeffounderror"
  • began with a very simple app, with just a few screens containing text, that wasn't working on < 4.2 devices, and began commenting chunks of code, until it could work on all phones;
  • uncomment back small pieces of code and make tests, until the problem was back again, to find where the problem was specifically located.

 

 

   Among other things, this is what I concluded from my (bad) experience:

  • noclassdeffounderror is thrown if I declare a variable (can be either local or static) of the type GameMIDlet (the name of my MIDlet class). This happens if I call Display.getDisplay( instance ).vibrate( 200 ), for example, and instance is the instance of my MIDlet.
  • someone also doesn't like when I declare internal classes in the MIDlet (moving them outside solved temporarily the error)
  • declaring static arrays like private static SomeObject[ ] myObjects in my classes is also disliked (looks like it only happens with my app classes; static String[ ] or static byte[ ] [ ] is fine, for example)
  • I have a compiled library, used all along the application, to encapsulate J2ME methods, such as drawing to the screen, rendering texts, forms, etc. Looks like the problem happens also if I extend one of this classes and the child class references a static object of the parent's class. Tried also to compile the library as a COD and adding it to the rapc import path, without success.

 


   It seemed that I was making some progress, but since I began to have problems again after making simple method calls (even if it was a static method with a fully commented body), I decided to stop and ask for help. This was looking much more a matter of faith than logic, and certainly it isn't supposed to be like this.

 

   Sorry if I didn't go further or skipped some details, but it's hard to give all details at once.

 

   I would be REALLY grateful if anyone can give me any help to solve this! 

 

 

best regards,

Peter

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

[ Edited ]

I might be missing something very simple here, but if you have created the jar file, then you have compiled your code, and if you have compiled it, then haven't you created a level dependent class (or classes) depending on the level of api jar that you have used in your compilation?

 

I don't know how you included the RIM API class in your Net Beans environment, but it seems to be whatever API library you have included probably defines the lowest level of OS on which your compiled code will run.

 

Just a thought, but note that I don't really understand what is going on here.  Just trying to help....

 

Edit: Sorry should have said - Welcome!  And I applaud your efforts to try and find the problem on your own!

Message Edited by peter_strange on 05-11-2009 07:17 PM
New Developer
peterhansen
Posts: 4
Registered: ‎05-11-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

Thanks for your reply!

 

   Regarding to the NetBeans compilation: I've already tried compiling it using JDE 4.1 and 4.2, and both produces the same effect. This applies to both my personal libraries and app specific classes. I've tried compiling an entire jar containing both specific and library files (which NetBeans do as default, and also works fine on dozens of apps and games I've written to hundreds of J2ME devices), and also compiling just the app-specific classes, and then adding my lib's jar file in "import" rapc parameter.

 

   I'll double-check that, but this looks odd to me anyway because in all cases rapc runs (apparently) without errors. Since I don't need anything too fancy, I'd like to compile the apps against 4.1, and then ensure maximum compatibility.

 

   I forgot to mention before that the jar files aren't obfuscated before passing them as parameters to rapc. I'll update the post as soon as I have news.

 

thanks,

Peter

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

Just to add a little bit of information that might be useful, I believe that RIM changed the format of the cod files between 4.1 and 4.2,  I believe that all rapc does is take the compiled jar and convert to a cod, so for maximum portability, I would run entirely 4.1 (or 4.0 if you can).  But I've never done anything like this, so this is entirely speculation, that I hope is useful.
New Developer
peterhansen
Posts: 4
Registered: ‎05-11-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

Hi,

Debugging with BlackBerry JDE i've discovered that this exception is thrown in class.forName( "screens.GameMIDlet" ) (which points correctly to my MIDlet class) at the application startup process.

I thought that this probably has something to do with the fact that this class extends a class named AppMIDlet, which in turn extends javax.microedition.midlet.MIDlet . Looks like rapc searchs for a class that extends a MIDlet, and then it will find AppMIDlet, when is not my application entry point. It then obfuscates GameMIDlet, changing its name and methods signatures, and then there "screens.GameMIDlet" doesn't exists when the application is running (please someone correct me if this is not the actual way rapc does its thing).

I had another shot: copied all my library classes to my project, and then compiled it all together. It was not enough: again the same noclassdeffounderror, no matter if I compile it against JDE 4.1, 4.2.0 or 4.2.1 .

Another test: I removed my mid-level MIDlet class, letting my app entry point extends javax.microedition.midlet.MIDlet directly. The code (finally) ran fine on a 8100 4.2.2 and on a 8700g 4.1.0!

But when I made some changes to the library so I won't need to copy all its files to each new project (after all, this is not what libraries are made for, right?), the problem was back, but I hope (at this point, faith is becoming more important than logic) that I'm just bypassing some basic library compilation step.

If I can manage this to work I'll let you know. If it doesn't, I'd like to anticipate a question: is there any unsupported J2ME class/resource in JDE 4.1 and 4.2 versions? Even if I comment ALL BlackBerry API imports, method calls, variables, etc I have in the code, this problem persists. Looks like some kind of limitation, such as number of classes, code size, method call depth that makes rapc generate a bad code.

I say this because a LOT of times I thought I had the solution, but it comes back from the dead to haunt me after some simple code insertions. I desperately need to go away from the trial-and-error path to a more solid, reliable and cafein-free path :-)


Peter
New Developer
peterhansen
Posts: 4
Registered: ‎05-11-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

Hello again everyone,

 

   just in case of anyone experiencing these weird results: I've finally found a workaround! I couldn't manage to solve this through RAPC compiler. The only way it seems to work is to copy ALL your source and resource files to a new directory (taking care of its tree hierarchy), create a new RIM JDE project (I'm using JDE 4.1) and compile it.

 

   I thought it would be enough to just copy all files to a directory and use RAPC compiler tool, but it put all my files on .jar/.cod root dir, so all packages and resources path got wrong (I couldn't manage to make the tool keep the original relative paths).

 

   Once one create a script file to copy everything to its place, generate a .jdp and a .jdw file (I can't copy my script here, but I assureit's easy to create your own script ), everything works nice and easy as they should be at first place. Not having to deal with random preverification errors really makes a programmer's life much easier :-)

 

best regards,

Peter

Developer
sblantipodi
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

I'm experiencing the same identical problem you are experiencing on your first post,

but I haven't understood hwo you solve this problem.

Developer
sblantipodi
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

problem solved,

I edit code with netbeans and prverify and compile it with JDE.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

Great.

 

Can you mark this and your other resolved Threads as solved?

Developer
sblantipodi
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: Problems when compiling application with JDE 4.2 or lower

can't do this since I'm not the author of the thread...