It’s been my experience that all MIDP implementations are different, but some are more different than others. BlackBerry Java smartphones are MIDP compliant, but they have a particularly unique flavor of MIDP. They’re also becoming increasingly popular, so I decided it was time to get one and try it out. Here’s my new (to me, actually used) BlackBerry 8700g:
By selecting “options > about” I got the convenient info screen above, which tells me that the version is 4.1 — one of the oldest BlackBerry handsets with Java. (That’s OK, all the better to test backwards compatibility.)
The first (and IMHO most annoying, but critical) step is to set up the development environment and get a complete “Hello World!” from code on the PC built and running on the device. Here’s my “road to Hello World” — the problems I encountered and their solutions — in hopes of saving the next person some time:
My first step was to load a few of my simplest sample MIDlets onto the device to see if they work. The Key Codes MIDlet worked fine — providing interesting information about which keystrokes the MIDlet can receive and which keystrokes are handled by the operating system while the MIDlet is running. The JSR Test MIDlet also worked and provided interesting information (once I figured out that the MIDlet commands are mapped to the trackwheel and that you press in the trackwheel itself to select). Installation was a breeze — just click on the Jar file’s URL in the browser, and the BlackBerry takes care of it. My simplest game — the Maze game — didn’t quite work, though, so I figured the next step was to download the BlackBerry-specific development utilities.
On the BlackBerry Java Application Development Tools & Downloads page, there are two choices: an Eclipse plugin, and a “legacy” standalone IDE. (I found this page through the Java Application Developers page — you may need to create an account and log in to see the development tools pages.) I assume the word “legacy” here means that they don’t intend to keep supporting it and they mean for you to switch to the Eclipse plugin. I tried them both, and I liked the standalone IDE better.
First, the Eclipse plugin. The spot where I wasted the most time was in trying to install the plugin into Eclipse 3.5 “Galileo”. If you read the getting started guide, it specifically states that the plugin works in Eclipse version 3.4. I assumed that it would also work on version 3.5 since the BlackBerry JDE Plugin for Eclipse page actually links to a download of Eclipse 3.5, and I just followed that link. But, when trying to install the plugin, I got the following error message:
To: net.rim.eide.componentpack4.7.0 [18.104.22.168]
Cannot complete the install because one or more required items could not be found.
Software being installed: BlackBerry Component Pack 4.7.0 22.214.171.124 (net.rim.eide.feature.componentpack4.7.0.feature.group 126.96.36.199)
Missing requirement: BlackBerry JDE Plug-in for Eclipse 188.8.131.52 (net.rim.eide 184.108.40.206) requires ‘bundle org.eclipse.core.resources [3.4.0,3.5.0)’ but it could not be found
Cannot satisfy dependency:
From: BlackBerry JDE Component Package 4.7.0 220.127.116.11 (net.rim.eide.componentpack4.7.0 18.104.22.168)
To: bundle net.rim.eide 0.0.0
Cannot satisfy dependency:
From: BlackBerry Component Pack 4.7.0 22.214.171.124 (net.rim.eide.feature.componentpack4.7.0.feature.group 126.96.36.199)
It looks like the plugin required a particular set of Eclipse core resources that it couldn’t find, which is the sort of thing that smells like a version mismatch. A little googling found me a site where I could download the Eclipse 3.4 “Ganymede” version, and the plugin installed in that Eclipse version just fine, according to the instructions in the links above.
the first drawback to the Eclipse plugin, however, is that it doesn’t appear to come with any sample code (or if it did, it’s well hidden). For that reason alone, you might as well download the BlackBerry JDE since it comes with a big pack of sample apps.
Installing the BlackBerry JDE, building the sample apps, and running them in the simulator was pretty straight-forward. There was one point, however, where I found the BlackBerry development environment – development guide to be a bit lacking. I felt like it should more clearly answer the following basic questions:
- Does the “project > build” command build the file that can be installed directly onto my device?
- If so, where is it???
I poked around a bit, and found the built .cod files in the same folder with the source code, interestingly enough. For the “Hello World” sample, that was “C:\Program Files\Research In Motion\BlackBerry JDE 4.1.0\samples\com\rim\samples\device\helloworld\com_rim_helloworld.cod”
Then the last step is to install it on the BlackBerry. Fortunately, the BlackBerry JDE came with a simple little command-line utility called “JavaLoader.exe” to install applications from the PC onto the BlackBerry device. So I connected the device via USB cable to my PC, allowed the PC to find an appropriate driver, and tried “JavaLoader -u dir” (to get the directory listing with the “-u” option indicating that I’m connecting via USB). Unfortunately, I got this crazy message:
Error: unable to open port
Sadly, no hints as to why it couldn’t open the port, so the next stop was to search the BlackBerry developer forums. This is the place to go — a quick search turned up the problem immediately: you need to be running the “BlackBerry Desktop Manager” in order for the JavaLoader to find the device. My used BlackBerry came with a couple of cables but no software, so again I turned to my old pal Google. I tried downloading two versions of the “BlackBerry Desktop Manager” for BlackBerry 4.1 from the BlackBerry site, and — this is the weirdest part of the whole adventure — I received some entirely different program instead. Not sure why. But cnet.com provided a link to a version of the Desktop Manager “tested spyware free”, and that one worked. Yay! With that desktop manager running, JavaLoader was able to connect to the device and load com_rim_helloworld.cod onto it.
That should be the last step, right?
Sadly, no. The HelloWorld application appeared on my main BlackBerry menu, but when I launched it, it threw an Exception! It failed to find its resource bundle! So I opened up the source code to see what was the problem. It turned out that it was importing packages from another sample application: “com_rim_demores.cod”. This is just a philosophical point, but I think the “Hello World” demo should be the simplest possible application — leave the best practices about internationalization for step 2 — but that’s just me. Anyway, with the resource demo application installed, the “Hello World” finally worked on my BlackBerry!
Now on to some actual development…