BlackBerry Hello World tutorial, the best one ever.

New developers always ask me the same questions: Where do I start programming? What is the best language to use? What’s the easiest language to use? It can be confusing, I know. With 1000′s of languages and environments, these questions are probably the most difficult to answer. Most of the time, I say “go f**k your hat.” (or variation, it’s my new favorite saying.)

Uhmm … What? This is a tutorial right?

I tell it how it is. If you don’t like it from the get go then you better get-going. BlackBerry dev is not easy. I wouldn’t recommend it to anyone starting out as a developer. It will make you frustrated and probably turn you away from development. I attempted BlackBerry development in college and I didn’t touch it again for almost 5 years because of how difficult it was. Check it out, my very first BB app, ever. Useless.

What? You’re still here? You are either a seasoned dev looking to get your hands on mobile or you are just damn crazy. Regardless, Good for you. Lets get on with it, shall we?

What do I need to make my first app for BlackBerry?

You have an amazing idea that will make you kazillions of dollars and you need to start developing right away. Where do you start? The first thing you have to do before you even touch a line of code is to make sure that you have setup your development environment for BlackBerry.

Come on, what’s the second thing?

Open Eclipse and enter the project name “helloworld”

eclipse new project

Right click in the Project Explorer window and click New -> Project -> BlackBerry Project.

You’ll get a screen that asks you to put in a project name. I always put whatever the project is supposed to be called in there, “HelloWorld”, to keep everything the same.

Click Finish. Not Next.

See the kazillion dollars yet? Soon.

Setup the project neatly.

I’ve worked with some shitty code in my time. The worst code in my opinion is hard-to-find code. It doesn’t matter what language you use, if statements, for-loop and all that can be fixed if you don’t like the code styling. Finding the code if it’s in convoluted place drives me crazy. Don’t do it, I’ll come delete your face.. I mean, harddrive.

On the left hand side of Eclipse, you should see your “helloworld” project. Click the tree arrow to expand and see the two project folders, src and res. The src folder is where we are putting our code. We want to add a package and then two class files.

I typically name the package something unique that I own, such as my URL or the clients URL that I’m working on. We then need a “Launcher” class to start the app, and then our “Screen” class.

Create a package that is named something unique for our main. I used com.gmg.hw.main

Right click on Src -> New -> Package -> Type “com.gmg.hw.main”.

Now create two class files, one named and one named

Right click on the package you created -> New -> Class -> Type “Scr_Main”

Repeat for “Launcher”

Lets code.

I know you want to compile and get started, so I won’t get into details of whats happening in the code inside of this blog post, instead I have provided comments in the code itself so you can try to understand what is going on.

Inside of, paste the following code.

package com.gmg.hw.main;

import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.ui.UiApplication;

class Launcher extends UiApplication
     public static void main(String[] args)
          // Create a new instance of the application.
          Launcher theApp = new Launcher();

          // To make the application enter the event thread and start processing messages,
          // we invoke the enterEventDispatcher() method.

     private Launcher()
          // Push the main screen instance onto the UI stack for rendering.
          this.pushScreen(new Scr_Main());

All you have to know here is that you create an instance of your application and you push the screen we are going to create inside of Scr_Main to the User Interface “Stack” on the BlackBerry – This means when the user clicks on your awesome icon, your Scr_Main gets displayed.

Here’s what’s going inside of Scr_Main.

package com.gmg.hw.main;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class Scr_Main extends MainScreen
	public Scr_Main()
		// Create a LabelField that we will display on the screen
		LabelField lf_hello = new LabelField();

		// Set the text you want in the label field
		lf_hello.setText("Hello, World!");

		// add the label field to our MainScreen

Still with me? Any BlackBerry application that shows info on the screen uses Fields. Common fields that are used can be LabelFields, HorizontalFieldManagers, VerticalFieldManagers, EditFields and many others.

With a few simple fields you can start laying out your BlackBerry Application the way you want it. In the Scr_Main example, I have created a LabelField where the “Hello World” text goes. The Scr_Main class extends MainScreen.

Lets run it.

That’s it. Hello World is now complete, so give it a run. Click Run, then Run Project. If your application doesn’t appear right away, it may be in the “Downloads” folder on your simulator.

You should end up with something like this.

If you got this far, then you have just completed Hello World, and you are ready to make your app that will change the world or at the very least, line your packets with dollars.

If you have any questions or comments, you know where to find me!

2 Responses to BlackBerry Hello World tutorial, the best one ever.

  1. Cory Fowler says:

    Great to see you publishing some stuff on your Blog. Keep up the Good work!

  2. Decent reading. Like your web design also. continue the good work.

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = seven

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>