Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Tutorial: Hello BlackBerry

The BlackBerry Java Plug-in for Eclipse provides templates you can use to create a basic app. You can customize the code in the template to suit your needs, or you can create an app from scratch with an empty template.

To get you started, we'll create a version of the "Hello World" app with the Hello BlackBerry template. This version of "Hello World" is a basic UI application that provides some simple UI components. The app includes an editable text field that allows the smartphone user to type text in a field; in this example, they can type their name. The app also includes a button field. When the smartphone user types their name and clicks the Say Hello to button, the app displays a dialog box with the text Hello <username> as shown in the following screenshot.

This screen shows the Hello BlackBerry UI.

Create the Hello BlackBerry app

In the BlackBerry Java Plug-in for Eclipse, make sure you turn on the BlackBerry Application Development perspective. Click Window > Open Perspective > Other and then choose BlackBerry Application Development

  1. From the BlackBerry menu, click New > BlackBerry Project.
  2. In the Project name field, type HelloBlackBerry.
  3. In the New BlackBerry Project dialog, select Create new project in workspace.
  4. Under JRE, select Use a project specific JRE and then choose BlackBerry JRE 7.0.0 from the dropdown list.
  5. Click Next.
  6. Click Next.
  7. Select the Hello BlackBerry template.
  8. Click Finish.

In the list of projects in the Package Explorer pane, the HelloBlackBerry project appears. You can expand the project to see that the src/mypackage folder contains two Java source files:

  • HelloBlackBerry.java: This file contains the source code for the main section of the app.
  • HelloBlackBerryScreen.java: This file contains the source code for generating the screen.

Running your app

You can run and test your app on a BlackBerry Smartphone Simulator or a BlackBerry smartphone.

The BlackBerry Java Plug-in for Eclipse includes simulators for various BlackBerry smartphone models. The simulators run the same Java code as the smartphones, so a simulator provides an accurate environment for testing how your app will function on a BlackBerry device.

Run your app in a simulator

In the following steps, we'll use the Hello BlackBerry app that we created earlier to demonstrate how to run an application.

  1. In the Package Explorer pane, select the project you want to run. For this example, select the HelloBlackBerry project.

  2. To run the app in a simulator, perform one of the following actions:

    • Right-click the project, and then select Run As > BlackBerry Simulator.

    • If you enabled the BlackBerry Application Development perspective, then from the BlackBerry toolbar, click the Run on BlackBerry Simulator button.

      The BlackBerry Java Plug-in for Eclipse builds and packages the project, and then launches the BlackBerry Smartphone Simulator.

  3. On the Home screen of the simulator, click the application icon. In this example, click the Hello BlackBerry icon.

    This screen displays the 9800 Simulator.

  4. To test the Hello BlackBerry app, type your name in the Enter Name field, and then click the Say Hello to button.

    A dialog box displays with the text Hello <your name> and an OK button. Click OK.

  5. To close the app on the simulator, press the Menu key, and then select Close.

  6. To close the simulator, click File > Exit.

Run your app on a smartphone

If your app uses protected Research In Motion APIs, you must first get code signing keys from RIM. For more information about code signing and registering with RIM to use protected APIs, see www.blackberry.com/SignedKeys.

  1. Connect the BlackBerry smartphone to your computer with a USB cable.

  2. In the Eclipse Package Explorer pane, right-click the project that you want to load on the device.

  3. Click BlackBerry > Load Project(s) on Device.

    The BlackBerry Java Plug-in for Eclipse builds and packages the project. If the smartphone is password-protected, you are prompted to type the password. The application is loaded on to the device.

  4. On the Home screen of the smartphone, click the application icon to run the app.