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

40 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.
 

40 Responses to “How to write your first BlackBerry application – Lesson 1: UI fields”


  1. 1 Paul

    SWEET! Thanks Fabian! I am so excited to try this!

  2. 2 SinisterJunkie

    Thanks so much for this series. Taking away any excuse I might have had to not try developing a few simple apps for my device and learning something new. Much appreciated.

  3. 3 Paul

    Hey why do I get an Error when Building it? I had to download the Java JDK 5 when I installed the JDE. Any ideas?

  4. 4 Fabian

    @paul What error do you get?

  5. 5 Paul

    @Fabian I didn’t have the Java SDK installed right. It needed the path variable.

    Hey what other resources do you recommend?

  6. 6 Fabian

    @Paul
    So it works now?
    Best thing is you go to supportforums.blackberry.com it’s a great resource for asking questions and so.

  7. 7 Kris

    how did you correct the error
    i think im getting the same one

    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

  8. 8 Peter

    Good article. If I can make a suggestion, it is recommended that you use specific event callbacks over FieldChangeListeners. For example:

    protected boolean navigationClick( int status, int time );
    protected boolean keyDown( int keycode, int status );
    protected boolean touchEvent( TouchEvent event );

    etc…

  9. 9 Peter

    Sorry just to add for clarification:

    ButtonField btnSubmit = new ButtonField(”Submit!”, ButtonField.CONSUME_CLICK) {
    protected boolean navigationClick( int status, int time )
    {
    // do your thang
    return true;
    }
    };

  10. 10 Ale

    Great! Waiting for lesson 2

    Thanks

  11. 11 Jim

    I thought I would give this a try but ran into a problem in that I cannot load or copy the two files to be added, Step 4, as I cannot find them. Where are they located. I dowloaded JDE 4.7 and JDE 4.7 components. Any other program requiremtns?

  12. 12 Fabian

    @Jim
    When you create a project then a folder is created where you define it. ther ein that folder you copy the files.

    @Ale
    thanks! please post here what you want to see in the next lesson!

  13. 13 Ale

    @Fabian
    Thanks for the answer, I’m interested in how intereact whit other BlackBerry’s applications, as email or send a file via BlackBerry Messenger. I don’t know If you can talk about it or it’s too complicated. Anyway, I’m sure your second lesson will be as good as this.

  14. 14 Fabian

    @Ale
    Ok, I will add ‘how to send emails’ in the next lesson.

  15. 15 Ale

    Ok perfect!!! ;) … I’m following you on twitter.

  16. 16 Dan

    If you get the error that others have mentioned, you must put the path to javac.exe in your PATH environment variable. To do this, go to System control panel, click Advanced, click Environment Variables, and double click PATH in the “System Variables” box. Enter in the path to the folder that contains javac.exe (mine was “C:\Program Files\Java\jdk1.5.0_19\bin”) after the other lines in the field (add a semicolon). Click OK and exit all the dialog boxes. Restart Blackberry JDE and you should be fine.

    Hope this helps.

  17. 17 Lee McArthur

    This is a great post – I went to school for Computer Science 10 years ago, and this is written so well I feel like I could dip my toe back into development again.

    For those of you looking to build BlackBerry applications to take to market without actually writing any Java code at all….

    [shameless promotion]

    Check out http://www.kryosvelocity.com. Velocity is a BlackBerry development platform, that enables you to deliver native Java BlackBerry applications, without reading one sentence about RIM API’s.

    Typical folks building apps with Velocity are web developers, and IT managers who “know enough to be dangerous”. One interesting anecdote: It has never taken a customer of ours more than 4 hours to build their own first prototype BlackBerry application using Velocity. I’m not talking about a Hello World application either: real data, through some security protocol, back to their own servers, pulling content via XML to build a real, useful, application.

    Check out the site and ping me if you are interested in a trial.

    [/shameless promotion]

    Thanks again for the great article. Looking forward to others in this series!

    Lee

  18. 18 moshe

    When i try to install JDE4.7 it points me to prereq JDK
    http://java.sun.com/javase/downloads/index_jdk5.jsp
    which one do i download for the sun ?

  19. 19 sheril

    really a good one…

  20. 20 Hank

    I am completely lost. I am getting the same errors as the others –

    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

    I have searched my entire harddrive and do NOT have a file called ‘javac.exe’ anywhere… what am I missing? Is there more to download and install than the JDE (4.7) from the RIM website?

  21. 21 chris

    I also get the error message” 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
    when trying to compile.
    I have been stuck on this for 2 days and am at my wits end

  22. 22 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

  23. 23 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.

  24. 24 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.

  25. 25 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?

  26. 26 edwin

    Is this for someone with any programming knowledge…

  27. 27 edwin

    Meant without …

  28. 28 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

  29. 29 christina

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

    Enjoy

  30. 30 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.

  31. 31 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.

  1. 1 How to write your first BlackBerry application - Lesson 1: UI fields | Blackberry News
  2. 2 How to write a BlackBerry application - Lesson 2: Mail API, Invoke API, Menu | BlackBerry Cool
  3. 3 How to write a BlackBerry application - Lesson 2: Mail API, Invoke API, Menu at SmartPhoneCool.com
  4. 4 How to Write a BlackBerry Application – Lesson 3: Create shortcuts and more - BBERRYNEWS
  5. 5 How to Write a BlackBerry Application - Lesson 3: Create shortcuts and more | BlackBerry Cool
  6. 6 How to write a BlackBerry application – Lesson 2: Mail API, Invoke API, Menu « Adrian Francis Weblog
  7. 7 How to write your first BlackBerry application – Lesson 1: UI fields « Adrian Francis Weblog
  8. 8 5 langkah mudah menulis program Blackberry - Blackberry Programming – Amri Shodiq
  9. 9 Start your first Blackberry Application – The beginning | Online Marketing Addict | Nganhtuan.com

Leave a Reply