Getting started with Developing and Debugging blackberry apps: OS 7.1, JDE 7 and Javaloader.exe


When my Windows Phone died (Dell Venue Pro 8GB) I picked up a BlackBerry Bold 9900 as a replacement (couldn't find a decent non-blackberry keyboard to save my life!). This got me into Blackberry phone development (previous BB dev has consisted of WebWorks applications for Playbook).

After a couple of days of trying to build & debug a Blackberry app, I can see that the road is long and the tools not as polished as what Microsoft and Apple offer. Case in point: I wanted to debug a simple 'hello world' application on my phone and couldn't figure out how to get it to work until now. I'd like to pass along my findings.

Update: Most of the issues went away when I switched from JDE to the 'Blackberry plugin for eclipse'. If you want to pursue Blackberry OS development, go with Eclipse and you will be less disappointed.

References:

Helpful resources:
  1. Running your application on a smartphone [developer.blackberry.com]
    1. Shows the CORRECT syntax for javaloader on BB 7.1
  2. Installing the Blackberry JDE on 64-bit Windows [accella.net]
  3. Tools for BlackBerry Java Development [developer.blackberry.com]


Misleading, Unhelpful or out of date resources:

  1. How To Use Javaloader [supportforums.blackberry.com]
    1. About 3 minutes in it tells you to use the -u switch which does NOT work any more
  2. JavaLoader - Load/Remove applications from BlackBerry Device without using BlackBerry Desktop Manager [bbdevtips.blogspot.com]
    1. Also indicates that you should use the -u switch
  3. Using the Blackberry Javaloader [enduserguides.com]
    1. Shows incomplete examples
    2. Indicates that the -u option should be used
  4. Load cod file to BlackBerry using JavaLoader [inteist.com]
    1. Shows the even older -u=USB syntax which does not work anymore
  5. Testing applications on a BlackBerry device [docs.blackberry.com]
    1. This doc tells you that it is possible to debug on a device, but doesn't tell you HOW to do it or WHERE to go to find out how to do it.
 

Well, that took awhile...

This time around I've listed a bunch of articles that did NOT work for me. I spent a good hour or so googling and only coming up with old, outdated results that did not work for me. Maybe my google search cookie has become corrupted? At any rate I was able to find what might possibly be the ONE article on the internet that describes how to load an app onto your Blackberry and wanted to pass that along.
 

Get started with JDE 7

To get debugging up and running with JDE (this is Not the Blackberry plugin for Eclipse) you need to do a few things:
  • Downlaod & an Oracle JDK (version 6 or higher- I went with JDK 7 update 6 )
    • Be sure to download the 32bit version! This is true even on x64 systems (JDE is x86 only)
       
  • Downlad & Install the Blackberry JDE
    • If you run into problems on Windows 7 x64, consult this article [accella.net]
       
  • For best results, be sure to install the appropriate version of the Blackberry Device OS + Blackberry Desktop from this site.
    • You will want to search for your mobile Carrier in the list.
       
  • Open the JDE (From Start -> All Programs)
    JDEInstartmenu.png

  • Create a new Workspace by going to File -> New Workspace...
    JdeCreateNewWorkspace.png

     
  • Give the workspace a name and location on the file system
     JdeCreateNewWorkspace2.png

  • Right-click on the name of the workspace and select Create new Project...
    JDECreatenewproject.png

    Then give it a Name and click ok
     JDECreatenewproject2.png

  • To create an actual Source code file, Right click on the project name and select Create new File in Project
    JdkcreatenewFile.png

    Then give the file a name with a .java extension

    JdkcreatenewFile2.png

    Note: The Filename *must* match the classname. In this case I'm borrowing some sample code that has a classname of HTTPFirstAvailable.
     
  • Enter your source code in the .java file that you just created. I used sample networking code from this blackberry page

  • Select the Build menu and click the Build button.
    • If all goes well you should see Build Complete appear in the bottom status-window.
    • You have just successfully build a .cod file (binary for BlackBerry phones)
 

Load your app on the Device

At this point things should be setup so that you can load the app on your Blackberry for debugging.. You COULD use the simulator that comes along with your device software, but i've had very little luck with that (hangs, freezes, crashes with regularity). Instead you should probably just test it on your own device.
 
Unfortunately, this is NOT a super-simple process like it is for Windows Phone developers or even a simple process like the iOS guys have. To debug on a real device there are multiple manual steps that need to be performed. Here we go:
 
  • Plugin your BlackBerry via USB
    • If the Blackberry Desktop manager prompts for a password, just say 'No'.
       
  • Open up a Dos Command Prompt and cd into your BlackBerry JDK folder. For me (OS 7.1) this path is:
    • C:\Program Files (x86)\Research In Motion\BlackBerry JDE 7.1.0\bin
       
  •  From within the DOS prompt, execute the following command (adapt to your .cod path):
    • javaloader.exe load "c:\path\to\myexecutable.cod"

      For clarity, here is a screen-cap of what the transfer process looks like:
      javaloaderexample.png



Start Debugging

At this point we are almost ready to debug! Just a few more steps and we can step through the code.

  • Within the JDE Environment, select Debug -> Attach to -> Handheld -> Device PIN
    • If you have multiple devices connected you should be able to pick which one to connect to. I only have one device connected in this example.
      JdeconnectToDevice.png

    • If you get an error that says something like "No debug information found for module 'net_rim_cldc'. Please ensure that you have installed the simulator package that matches the handheld code you are attempting to debug.", don't panic.
      JdeDebugError.png
      Apparently this happens if you don't have an exact software match between what is installed on the PC and the BB. I am still able to debug when i see this error.

  • From within JDE, set a breakpoint on a line of code (right-click -> Set breakpoint at cursor)
     
  • From the Device run the program (Should be placed on the home screen if the javaloader step was successful)
     
  • The break-point should be hit, and you'll be able to step through the code and investigate variable states as you please.

 

Congratulations! You are all setup to create and Debug Blackberry OS 7.1 applications on real BB device. :)

Here's what the debugger window looks like in JDE 7:

jdedebuggerwindow.png