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.
 

  • Paul

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

  • Paul

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

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

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

  • 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?

  • 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?

  • http://www.twitter.com/FabianMH Fabian

    @paul What error do you get?

  • http://www.twitter.com/FabianMH Fabian

    @paul What error do you get?

  • http://www.twitter.com/FabianMH Fabian

    @paul What error do you get?

  • http://www.twitter.com/FabianMH Fabian

    @paul What error do you get?

  • Paul

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

    Hey what other resources do you recommend?

  • Paul

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

    Hey what other resources do you recommend?

  • http://www.twitter.com/FabianMH 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.

  • http://www.twitter.com/FabianMH 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.

  • Kris

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

    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

  • 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

  • http://m.mypoynt.com/ 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…

  • http://m.mypoynt.com/ 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…

  • http://m.mypoynt.com 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…

  • http://m.mypoynt.com/ 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;
    }
    };

  • http://m.mypoynt.com 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;
    }
    };

  • Ale

    Great! Waiting for lesson 2

    Thanks

  • Ale

    Great! Waiting for lesson 2

    Thanks

  • 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?

  • 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?

  • http://www.twitter.com/FabianMH 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!

  • http://www.twitter.com/FabianMH 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!

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

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

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

  • http://www.twitter.com/FabianMH Fabian

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

  • http://www.twitter.com/FabianMH Fabian

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

  • Ale

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

  • Ale

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

  • 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 FilesJavajdk1.5.0_19bin”) 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.

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

  • http://www.kryosvelocity.com/ 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

  • http://www.kryosvelocity.com 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

  • 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 ?

  • 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 ?

  • sheril

    really a good one…

  • sheril

    really a good one…

  • sheril

    really a good one…

  • Hank

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

    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

    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?

  • 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?

  • chris

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

  • chris

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

  • chris

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

  • 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

  • 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