How to write your first BlackBerry application – Lesson 1: UI fields

149 Comments

software development

This article is the first in a series of articles about BlackBerry development. With App World, third party software vendors and the web, there are a ton of opportunities for an independent developer to make money.

BlackBerry Development in Java – Lection 1: Basic fields in the User Interface

Let’s get right into it. Download the JDE (Java Development Environment) from the BlackBerry website. I personally used the JDE 4.3 for this project but you can also download a newer JDE. For advanced functions like using the BlackBerry Storm accelerometer or touch screen, you have to install JDE 4.7.

For advanced features and other APIs you may want to use, you need code-signing keys from RIM. You can purchase signing keys here. The keys cost $20 which is a bargain considering you can use the keys forever, and they’re going to help you make a great BlackBerry application. Make sure to read more about the keys because they’re an important part of BlackBerry development.

For this introductory application, you don’t need signature keys and the compiled *.cod file can be run on the device (and not only on the simulator).
 
How to setup the JDE:

After installation of the JDE, launch it and then click on:

    1. File -> New
    2. Workspaces – Tab
    3. Name it Lections
    4. Click OK

Then on the left side in the JDE, you see the Tab Files. Click on:

    1. Lections.jdw (Right click)
    2. Select Create new Project
    3. Name it Lection_1
    4. Copy the two files GreetingScreen.java and HelloWorld.java into the same folder where the Lesson_1.jdp file is (the main project folder)
    5. Click on Add File to Project and select both *.java files
    6. Now both *.java files appear under Lection_1
    7. Click on those in the list to open them up in the JDE
    8. Now you’re ready to go, you have successfully imported the files and can now work with them.
    9. Press F7 to compile the application or press F5 to run the application on the simulator.
    10. The application is compiled to a *.cod file.
    11. The *.alx file (for Desktop Manager installation) needs to be created manually by the user:
    1. Right click on Lection_1 and then on Generate ALX file.
    2. Now the *.alx file is created and the application can be installed via Desktop Manager.
    3. The *.alx file and the *.cod file have to be in the same folder for installation.

That’s how the ‘Files’ should look like on the left side of the screen:

BlackBerry Development 1
 
The *.java Files:
 
We have two *.java files for our Project. The one is the HelloWorld.java file and the other one is the GreetingScreen.java file.
 
The HelloWorld.java file does the following:

You want your application to show the user a graphical user interface; that’s why you need your HelloWorld class to extend the UiApplication class. The UiApplication class can be found here in the APIs: net.rim.device.api.ui.UiApplication.

A BlackBerry application always starts with the main() method. In the main() method the first thing that happens is that an instance is created by calling the constructor. The constructor uses the UiApplication class to use the pushScreen() method to show the GreetingScreen.
 
The GreetingScreen.java file is a bit more complicated but if you follow the comments then you will soon find out what it does.
 
So what does the application actually do?

This is the main screen of the application; it contains a ButtonField, a Title, a LabelField, a SeparatorField and an EditField.

BlackBerry development lesson 1

When you click on the Button, then it displays a message with the name you entered in the EditField.

BlackBerry development

And when you quit the application then it also shows a message with the text from the field.

BlackBerry development
 
If you still have questions, just follow me on Twitter: twitter.com/FabianMH

ED NOTE: Check out Fabian’s software page. He’s got some useful apps to improve your BlackBerry experience, as well as some cool BlackBerry Storm software.
 

  • Kirk Wayland

    I get this error when I try to build… Suggestions?

    Building Lection_1
    C:Program FilesResearch In MotionBlackBerry JDE 4.7.0binrapc.exe -quiet import=”….Program FilesResearch In MotionBlackBerry JDE 4.7.0libnet_rim_api.jar” codename=Lection_1 Lection_1.rapc warnkey=0×52424200;0×52525400;0×52435200 C:gatekeeperjavahelloworld.java C:gatekeeperjavagreetingscreen.java
    I/O Error: CreateProcess: javac -source 1.3 -target 1.3 -g -O -d C:DOCUME~1kwaylandLOCALS~1Temprapc_12b93724.dir -bootclasspath “….Program FilesResearch In MotionBlackBerry JDE 4.7.0libnet_rim_api.jar” -classpath “….Program FilesResearch In MotionBlackBerry JDE 4.7.0libnet_rim_api.jar” C:gatekeeperjavahelloworld.java C:gatekeeperjavagreetingscreen.java error=2
    Error while building project

  • Kirk Wayland

    I get this error when I try to build… Suggestions?

    Building Lection_1
    C:\Program Files\Research In Motion\BlackBerry JDE 4.7.0\bin\rapc.exe -quiet import=”..\..\Program Files\Research In Motion\BlackBerry JDE 4.7.0\lib\net_rim_api.jar” codename=Lection_1 Lection_1.rapc warnkey=0×52424200;0×52525400;0×52435200 C:\gatekeeper\java\helloworld.java C:\gatekeeper\java\greetingscreen.java
    I/O Error: CreateProcess: javac -source 1.3 -target 1.3 -g -O -d C:\DOCUME~1\kwayland\LOCALS~1\Temp\rapc_12b93724.dir -bootclasspath “..\..\Program Files\Research In Motion\BlackBerry JDE 4.7.0\lib\net_rim_api.jar” -classpath “..\..\Program Files\Research In Motion\BlackBerry JDE 4.7.0\lib\net_rim_api.jar” C:\gatekeeper\java\helloworld.java C:\gatekeeper\java\greetingscreen.java error=2
    Error while building project

  • Kirk Wayland

    OK, Putting the path to directory that contained JAVAC.EXE, (and then rebooting), fixed the build issue. Next issue is that the Simulator does not seem to know about the application. How does one run this on the simulator? I selected DEBUG, (provate and released being the other choices), and hit F5. The simulator runs, takes forever and a day to load, and looks and feels like a Blackberry – except no Lection_1 application anywhere to be found.

  • Kirk Wayland

    OK, Putting the path to directory that contained JAVAC.EXE, (and then rebooting), fixed the build issue. Next issue is that the Simulator does not seem to know about the application. How does one run this on the simulator? I selected DEBUG, (provate and released being the other choices), and hit F5. The simulator runs, takes forever and a day to load, and looks and feels like a Blackberry – except no Lection_1 application anywhere to be found.

  • Kirk Wayland

    OK, Putting the path to directory that contained JAVAC.EXE, (and then rebooting), fixed the build issue. Next issue is that the Simulator does not seem to know about the application. How does one run this on the simulator? I selected DEBUG, (private and released being the other choices), and hit F5. The simulator runs, takes forever and a day to load, and looks and feels like a Blackberry – except no Lection_1 application anywhere to be found.

  • Kirk Wayland

    OK, Putting the path to directory that contained JAVAC.EXE, (and then rebooting), fixed the build issue. Next issue is that the Simulator does not seem to know about the application. How does one run this on the simulator? I selected DEBUG, (private and released being the other choices), and hit F5. The simulator runs, takes forever and a day to load, and looks and feels like a Blackberry – except no Lection_1 application anywhere to be found.

  • Kirk Wayland

    OK, Putting the path to directory that contained JAVAC.EXE, (and then rebooting), fixed the build issue. Next issue is that the Simulator does not seem to know about the application. How does one run this on the simulator? I selected DEBUG, (private and released being the other choices), and hit F5. The simulator runs, takes forever and a day to load, and looks and feels like a Blackberry – except no Lection_1 application anywhere to be found.

  • Kirk Wayland

    “Lection_1.debug not found”. I cannot seem to find a setting anywhere in the IDE that will generate the debug file that the Simulator wants.

    Is there a better IDE out there somewhere?

  • Kirk Wayland

    “Lection_1.debug not found”. I cannot seem to find a setting anywhere in the IDE that will generate the debug file that the Simulator wants.

    Is there a better IDE out there somewhere?

  • edwin

    Is this for someone with any programming knowledge…

  • edwin

    Is this for someone with any programming knowledge…

  • edwin

    Is this for someone with any programming knowledge…

  • edwin

    Meant without …

  • edwin

    Meant without …

  • Darrell Bosely

    This problem appears on any demo app (from the Samples) that I try to run.
    (I have just installed the Blackberry JDE).
    What I do: 1- Bring in all the samples with ‘Open Workspace’
    2- Set Active Workspace (for example ‘HelloWorld’)
    3- Select Build (F7) Get ‘Build Complete’ with no errors shown.
    4- Select ‘Debug/Go’ (F5)
    5- The Simulator (For 8310- I have an 8330) and the hour glass works
    6- After a bit the ‘Cannot find file’ dialog appears with this
    message: ‘CMBUnitsConverter$2drimbb8300.debug’
    7- I click ‘Don’t ask this again’ and eventually I get (where the
    code was) a screen full of ‘source code is not available’.
    8- I also see in the bottom right corner pane:
    Exception thrown @24008000 net.rim.device.api.i18n
    MissingResourceException’

    What’s wrong? What am I missing?

    Thanks in advance.
    Darrell Bosely

  • Darrell Bosely

    This problem appears on any demo app (from the Samples) that I try to run.
    (I have just installed the Blackberry JDE).
    What I do: 1- Bring in all the samples with ‘Open Workspace’
    2- Set Active Workspace (for example ‘HelloWorld’)
    3- Select Build (F7) Get ‘Build Complete’ with no errors shown.
    4- Select ‘Debug/Go’ (F5)
    5- The Simulator (For 8310- I have an 8330) and the hour glass works
    6- After a bit the ‘Cannot find file’ dialog appears with this
    message: ‘CMBUnitsConverter$2drimbb8300.debug’
    7- I click ‘Don’t ask this again’ and eventually I get (where the
    code was) a screen full of ‘source code is not available’.
    8- I also see in the bottom right corner pane:
    Exception thrown @24008000 net.rim.device.api.i18n
    MissingResourceException’

    What’s wrong? What am I missing?

    Thanks in advance.
    Darrell Bosely

  • http://theblackberryreview.blogspot.com/ christina

    I have a review on me blog for some guides relating to blackberry app development and Java. http://theblackberryreview.blogspot.com/

    Enjoy

  • http://theblackberryreview.blogspot.com/ christina

    I have a review on me blog for some guides relating to blackberry app development and Java. http://theblackberryreview.blogspot.com/

    Enjoy

  • sgr

    I use Blackberry JDE 4.7.0.41. I did everything as per this article. When I launch the Simulator, I don’t see any App. What kind of Simulator settings I need so I can view the App. (I use Default Simulator now)

    I would appreciate any help. Thanks.

  • sgr

    I use Blackberry JDE 4.7.0.41. I did everything as per this article. When I launch the Simulator, I don’t see any App. What kind of Simulator settings I need so I can view the App. (I use Default Simulator now)

    I would appreciate any help. Thanks.

  • Thomas Klonowski

    I’m having the same problem as sgr. The simulator takes forever to load and there is no sign of the application. You say that you can load the application through the desktop manager. Where and what is the desktop manager? You have to provide complete instructions if you want users to follow your tutorial. Thanks.

  • Thomas Klonowski

    I’m having the same problem as sgr. The simulator takes forever to load and there is no sign of the application. You say that you can load the application through the desktop manager. Where and what is the desktop manager? You have to provide complete instructions if you want users to follow your tutorial. Thanks.

  • Marius

    @sgr
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    !ATTENTION!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    To fix all problems regarding a missing PATH (which is required for the java file to compile, please see
    http://www.blackberryforums.com/rim-software/79668-jde-build-all-problem.html

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Can’t figure out how to run the actual application??
    :::
    After following the above steps, and you hit F5. Then let the simulator load to the main blackberry menu.
    Go to the Menu, select the Downloads folder.
    You will see your app in there
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • http://~ Marius

    @sgr
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    !ATTENTION!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    To fix all problems regarding a missing PATH (which is required for the java file to compile, please see
    http://www.blackberryforums.com/rim-software/79668-jde-build-all-problem.html

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Can’t figure out how to run the actual application??
    :::
    After following the above steps, and you hit F5. Then let the simulator load to the main blackberry menu.
    Go to the Menu, select the Downloads folder.
    You will see your app in there
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • Vishnu

    hai….
    please reply…

    Anyone know how to read acceleration data via Blackberry accelerometer….
    and i want the output to be converted to miles-per-hour….so that the application will work as a speedometer…..it would be a great help, if someone could provide me the pseudo code……..

    Is it possible to do that ….someone please help me………!!!!!!!

    Thanks in advance…..

  • Vishnu

    hai….
    please reply…

    Anyone know how to read acceleration data via Blackberry accelerometer….
    and i want the output to be converted to miles-per-hour….so that the application will work as a speedometer…..it would be a great help, if someone could provide me the pseudo code……..

    Is it possible to do that ….someone please help me………!!!!!!!

    Thanks in advance…..

  • Vishnu

    hai….
    please reply…

    Anyone know how to read acceleration data via Blackberry accelerometer….
    and i want the output to be converted to miles-per-hour….so that the application will work as a speedometer…..it would be a great help, if someone could provide me the pseudo code……..

    Is it possible to do that ….someone please help me………!!!!!!!

    Thanks in advance…..

  • Vishnu

    hai….
    please reply…

    Anyone know how to read acceleration data via Blackberry accelerometer….
    and i want the output to be converted to miles-per-hour….so that the application will work as a speedometer…..it would be a great help, if someone could provide me the pseudo code……..

    Is it possible to do that ….someone please help me………!!!!!!!

    Thanks in advance…..

  • Mark

    For the life of me i can’t get JDE 4.7 or 5.0 to work with windows 7 is the process muc h different for Eclipse with the blackberry plugin? becaused i got that working.

  • Mark

    For the life of me i can’t get JDE 4.7 or 5.0 to work with windows 7 is the process muc h different for Eclipse with the blackberry plugin? becaused i got that working.

  • hendra

    I GET ERROR MESSAGE…..LESSON 1
    Building Lections_1
    C:Program FilesResearch In MotionBlackBerry JDE 4.3.0binrapc.exe -quiet import=..libnet_rim_api.jar codename=Lections_1 Lections_1.rapc warnkey=0×52424200;0×52525400;0×52435200 “C:Program FilesResearch In MotionBlackBerry JDE 4.3.0bingreetingscreen.java” “C:Program FilesResearch In MotionBlackBerry JDE 4.3.0binhelloworld.java”
    I/O Error: Cannot run program “javac”: CreateProcess error=2, The system cannot find the file specified
    Error while building project

  • hendra

    I GET ERROR MESSAGE…..LESSON 1
    Building Lections_1
    C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin\rapc.exe -quiet import=..\lib\net_rim_api.jar codename=Lections_1 Lections_1.rapc warnkey=0×52424200;0×52525400;0×52435200 “C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin\greetingscreen.java” “C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin\helloworld.java”
    I/O Error: Cannot run program “javac”: CreateProcess error=2, The system cannot find the file specified
    Error while building project

  • John

    For people getting the JavaC error. First make sure you have the prerequisite installed. You will know if you do or not when you go to install the Black Berry JDE. A pop up will come up saying that you are missing something and direct you to what you have to download. After you download the prerequisite try to run the BB JDE program and compile. If you’re still getting the JavaC error in Windows go to CONTROL PANAL->SYSTEM->ADVANCED->ENVIORMENT VARIABLES. You should see in the user variables box and a variable labeled “PATH”. This should be pointing to the JavaC compiler which is a physical file that can be searched called javac.exe. Mine was located in “C:SunSDKjdkbin” so my variable now looks like this “PATH C:SunSDKjdkbin”. If you don’t have a PATH variable create it. If you do have one edit it to point to the JavaC compiler. Once this is done restart the BB JDE and recompile it should work then.

    If you get it to compile (F5) but can’t see your program on the BB simulator make sure you navigate the simulator with your arrow keys and not the mouse. It sounds stupid (and is stupid) but for about 30 mins I was clicking the LCD trying to figure out how to see my program until I realized you use the arrow keys to navigate.

  • John

    For people getting the JavaC error. First make sure you have the prerequisite installed. You will know if you do or not when you go to install the Black Berry JDE. A pop up will come up saying that you are missing something and direct you to what you have to download. After you download the prerequisite try to run the BB JDE program and compile. If you’re still getting the JavaC error in Windows go to CONTROL PANAL->SYSTEM->ADVANCED->ENVIORMENT VARIABLES. You should see in the user variables box and a variable labeled “PATH”. This should be pointing to the JavaC compiler which is a physical file that can be searched called javac.exe. Mine was located in “C:\Sun\SDK\jdk\bin” so my variable now looks like this “PATH C:\Sun\SDK\jdk\bin”. If you don’t have a PATH variable create it. If you do have one edit it to point to the JavaC compiler. Once this is done restart the BB JDE and recompile it should work then.

    If you get it to compile (F5) but can’t see your program on the BB simulator make sure you navigate the simulator with your arrow keys and not the mouse. It sounds stupid (and is stupid) but for about 30 mins I was clicking the LCD trying to figure out how to see my program until I realized you use the arrow keys to navigate.

  • vivekkumarsrivastava

    good content.

    >>> I have one problem- When we run one blackberry project on different computer then cod file is not generate

  • Luke

    I had the PATH error, fixed (thanks so much for the commenters who helped with it). However, I'm still getting an “Error while building project” due to:

    I/O Error: Lection_1Lection_1.tmp (Access is denied)

    Any ideas?

  • grrr

    I dont know you that much… but can you please develop grindr for blackberry…! or another gps based chat for bb…
    there are lots of apps for shitty iphone… but there is not one single usefull apps for bb :(

  • Roxxi23

    ….ok im new to this stuff. I followed every step and the default simulater popped up and it looks like the program is running in the background. I got a simulated msg that said “Do you want to run CDMA…” something like that. I used the arrow keys and highlighted one or the other, not sure which, then toggled to the lesson because i didn't recall reading anything about this happening. when i still didn't read anything, i tolggled back to the simulator and it's now blank again, with the program still running on the jde. Anyone know what I did wrong???

  • Roxxi23

    Why am I getting this error?????:

    Building Lecticons_1
    C:Program FilesResearch In MotionBlackBerry JDE 4.7.0binrapc.exe -quiet import=..libnet_rim_api.jar codename=Lecticons_1 Lecticons_1.rapc warnkey=0×52424200;0×52525400;0×52435200 “C:Documents and SettingsRoxann CasiasDesktopjava lessonsgreetingscreen.java” “C:Documents and SettingsRoxann CasiasDesktopjava lessonshelloworld.java”
    I/O Error: CreateProcess: javac -source 1.3 -target 1.3 -g -O -d C:DOCUME~1ROXANN~1LOCALS~1Temprapc_4ca3c3f3.dir -bootclasspath ..libnet_rim_api.jar -classpath ..libnet_rim_api.jar “C:Documents and SettingsRoxann CasiasDesktopjava lessonsgreetingscreen.java” “C:Documents and SettingsRoxann CasiasDesktopjava lessonshelloworld.java” error=2
    Error while building project

  • Marco Faustinelli

    You're very right, Thomas. This article is either obsolete or inaccurate. In the case of the newer 9530 simulator you've got to load the .cod file thru menu File->Load Java Program and after that you click once or twice on the screen till you see there a darn directory called Downloads (!?!?!) where the app is available. Two hours thrown away just to find that out. It is a shame that this page so high on Google is actually no more than a worn out stub.

  • Bob

    you cannot figure out the speed (mph) from accelerometer date. GPS data can help you with speed.

  • Bob

    you cannot figure out the speed (mph) from accelerometer date. GPS data can help you with speed.

  • kyle nelson

    help me my mobile turns on and then it says application error and needs to be reset what can i do?

  • leem

    Hai John.

    I went used your suggestion and made a path (pointing to the Parent folder of javac.exe).

    Now when I try to compile I still get this error:

    I/O Error: Cannot run program “javac”: CreateProcess error=2, The system cannot find the file specified

    How do I solve it?

  • http://twitter.com/Bloke28 Adam B

    Thats awesome, I had to do what john said in comments only the directory for me was different.
    My PATH=”c:Program FilesNVIDIA CorporationPhysXCommon;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;C:Program FilesJavajdk1.5.0bin”
    I only added this line “;C:Program FilesJavajdk1.5.0bin” to the end of the PATH and restart Blackberry JDE to make it compile and run in emulator successfully.
    Can anyone recommend any open source sites for J2ME code?
    AND FABIANMH can you add Bloke28 to twitter please, and allow my request to follow you too.

  • Rock Ramma

    Great post but .. this is what I get. I have seen some others here complaining about the same issue but didn’t see any solution. I am a first timer so sorry if I am just being stupid

    thanks

    Building lection_1
    C:Program FilesResearch In MotionBlackBerry JDE 6.0.0binrapc.exe -quiet codename=lection_1 lection_1.rapc warnkey=0×52424200;0×52525400;0×52435200 import=..libnet_rim_api.jar “C:Program FilesResearch In MotionBlackBerry JDE 6.0.0bingreetingscreen.java” “C:Program FilesResearch In MotionBlackBerry JDE 6.0.0binhelloworld.java”
    Error while building project

  • Phil1

    i have no idea of programming, and would like to know what would be involved
    in order to create an app that takes an email msg content and can transfer the email content onto a special app platform with customised editing tools ?

    pls advise

  • Ian 1324

    I clicked f7 and there is NO FUCKING .COD FILE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I clicked create alx file and it made an alx file correctly. BUT WHERE IS MY FUCKING COD FILE? F7 F7 F7 F7 F7 NO COD FILE ANYWHERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • The Dude

    wow dude you need to calm down man!

  • Femiolubosi

    yeah u gotta calm down. what da….!!