New BlackBerry Project
So, now that you have all the required tools properly set up (from Setting up the Environment), let’s check if everything is OK in our environment. As you probably know, the most common example in every developer language is the classic “helloworld” project. This time, instead of creating the classes ourselves, we will use the BlackBerry sample project that comes with our environment.
To import this and other sample projects you just have to follow these steps:
- Launch your eclipse IDE.
- Go to File>Import.
- Select BlackBerry>Import BlackBerry Samples.
- A new window with all the available samples will be opened.
- Deselect all and select just the helloworld demo.
- Click Finish.
You will see your new project called HelloWorldDemo in your package explore tab. You will also notice that a new window has opened. This is a valuable help window integrated with our Eclipse environment with a lot of useful resources and links. Close this window right now, but later it will be a perfect companion to help improve your knowledge of BlackBerry Java development.
Let´s check our code and explain some concepts and after that we will try to launch our helloworld sample in a simulator. If you open the only Java class the project has, HelloWorldDemo.java you see the following:
public class HelloWorldDemo extends UiApplication
As you can see our class extends from UiApplication, which is the base class for all device applications which provide a user interface. This is because the main purpose of this helloworld class is just showing a screen with the classic text “Hello World”. If you don’t need any user interface, you could extend Application, which is another base class. Of course, BlackBerry is MIDP 2.0, CLDC 1.1 compliant so you can also extend from MIDlet and create a j2me application. We will see that in future articles.
The following code will be detailed in the next few articles but at the moment, you can see that the class constructor just pushes a HelloWorldDemoScreen which extends a MainScreen object to the device Screen.
This HelloWorldDemoScreen is just a basic main screen with the text “Hello World” and a Dialog alert saying “Goodbye” which is prompted when the screen is closed.
Let’s see if it works. You just need to run your project by going to the Eclipse Run button>Run As>BlackBerry Simulator.
This will launch the default BlackBerry Simulator, which is BlackBerry 9550 Storm 2 model, with our application installed. You can find it in Menu>Downloads. If you launch it, you should see something like this:
How to Select a new Simulator Model
If you want to test your application in a specific device simulator, you can download it from the RIM website. There you can even select the carrier of your selected device so as to provide the test with the most similar environment the application will find in the future.
To configure a new simulator, press Run Button>Run Configurations. Create and name a new configuration under BlackBerry Simulator. Once created, change the desired device under Simulator>General tab. Press Apply and Run and the new simulator model should be prompted.
In the next article, we will see which files are created when building your code and we will delve into how to launch an app on a device.
This post is part of the series: How to Start BlackBerry Application Development
This is a guide for beginners to show you how to get set up and begin developing applications for a BlackBerry device.
- How to Start Developing Java applications for BlackBerry Devices: Setting up the Environment
- How to Start Developing Java Applications for BlackBerry Devices: Working with the Simulator
- How to Start Developing Java Applications for BlackBerry Devices: Working with Devices
- How to Start Developing Java applications for BlackBerry Devices: Signing Keys