Wednesday, April 25, 2007

Blackberry 7290 application OutOfMemory exception

After testing my application on the simulator, I finally loaded it onto a real blackberry device, model 7290. It was very exciting to see the cute little logo shown up on the screen. Rolling the trackwheel and click, I got an "OutOfMemory" exception thrown right at my face!!! What a bummer.

Both from the Blackberry documentation and the Internet posts, I got the impression that mobile devices have VERY limited memory, just enough to hold some objects and some object references (handlers). So it must be my application using too much memory. I guess there can only be one response from any developer: I need to optimize my code.

So I started optimizing my code, reducing all object creations and references that are not absolutely necessary, sometimes even sacrifice design patterns, best practices and code readability. I guess that is the price you have to pay for efficiency. Did it help? NO.

I was just about to start doing object grouping when I ran over a post on Internet saying it is not your application, it is the JDE version you are using. For the particular device model (7290) and OS version, I need to use Blackberry JDE4.0 versions. The mystery and embarassing OutOfMemory problem was solved just like that.

Eclipse BlackBerry JDE ClassNotFound Exception

Environment: Eclipse 3.1.1, BlackBerry JDE 4.2.1

When I first set up my eclipse for BlackBerry development, I got this exception: The type net.rim.device.internal.ui.Cursor cannot be resolved. It is indirectly referenced from required .class files. After searching the the Internet and the blackberry java forum, I figured out that it is caused by the java compliance level setting. To fix it, go to Window - Preferences - Java - Compiler, set the Java Compliance Level to 1.4.

Monday, April 23, 2007

DocumentBuilderFactory code signing issue

After resolving the outofmemory issue, my code still won't run. I got another exception saying: Error starting : Module must be signed with the RIM Runtime Code Signing Key (RRT).

Hmm, I was pretty sure that I am not using any signed API, but out of 3000 lines of code, it is very much possible to miss one or two. JDE 4.2.1 has a feature that can outline all the signed API calls. It helps only if I can get it working.

Before I eyeball the code line by line, I did a google search and found this post. Ahha, it is a bug in JDE. The DocumentBuilderFactory falsely requires code signing (fixed in 4.2 and higher). Now my only way out is to buy a sign key from RIM.

Accessing remote X-window from windows box

This is not pretty, but it's needed sometimes. (Yeah, I know, your company made you use windows)

There is a good deal of information on this wiki page about Cygwin/X. But to me it seems like too much information so I simplified it for my own reference.

Here are three simple steps to access remote X after you get Cygwin with X installed:

  1. open a Cygwin window and start X server: X -multiwindow &
  2. export DISPLAY=
  3. ssh -X username@remote.server
  4. run xclock (personally I prefer xeyes) to test
One thing to keep in mind is that the remote server has to enable X11 forwarding. It is configed in sshd config file /etc/ssh/sshd_config. Search for X11Forwarding.

That is it. If you prefer putty which is another nice tool I use occationally. You can do this:
  1. open a Cygwin window and start X server: X -multiwindow &
  2. Open putty, in Connection --> SSH --> X11 tab, check the box "Enable X11 Forwarding".
  3. Login and you are done, now open an X app like xclock or xeyes, you should see it.