Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
Creating your first MIDlet using EclipseME
We are assuming that you've installed Java ME development tools according to the article Installing Java ME development tools for Symbian.
Create a new project
- Start Eclipse, and go to the workbench. (If you are unaware of Eclipse concepts such as the "workbench", now is a good time to use the Help function to learn the basics.)
- Select the menu item File | New | Project.
- Expand node J2ME and select J2ME Midlet Suite. Press Next.
- Give the project name HelloWorld. You can also change the workspace location to be different from the default. Press Next.
- Select Sun Java(TM) Wireless Toolkit 2.5.2 for CLDC and DefaultColorPhone. (Selecting S60 3rd Edition FP2 SDK for MIDP and S60Device will cause running the MIDlet to fail, with an dialog displayed, saying that the Jar file could not be initialized because of a caught exception.) Press Next.
- In tab Source, check the checkbox Allow output folders for source folders, and accept the default.
- Press Finish.
Eclipse's package explorer should show a newly created project HelloWorld, which includes folders src and res, library J2ME library, and JAD file HelloWorld.jad.
Create a new MIDlet
- Select the menu item File | New | Other.
- Expand node J2ME and select J2ME Midlet. Press Next.
- A dialog with the title J2ME Midlet appears.
- The Source folder setting item should already be set to <your workspace location>/src.
- For the Package setting item, give the name com.example.helloworld.
- For the Name setting item, give the name HelloWorldMidlet.
- Press Finish.
You should now see a newly created file HelloWorldMidlet.java in Eclipse's editor window, with some skeleton code. Eclipse's package explorer should show that it has been created under HelloWorld/src/com.example.helloworld.
Write MIDlet code
Replace the code of HelloWorldMidlet.java with the code from article Hello World in Java ME.
Debug MIDlet code
- Set a breakpoint at the start of method startApp.
- In the Package Explorer, right-click on HelloWorldMidlet.java, select Debug As, and then Emulated J2ME Midlet.
- A dialog comes up asking if you want to switch to the Debug perspective. Press Yes.
- The phone emulator window should now be displayed. Eclipse should have switched to the Debug perspective, and in the editor window, the execution of the MIDlet should have stopped at the breakpoint you set.
- Resume execution. The emulator's screen should now display "Hello Hello World!"
Create a deployment package
- In the Package Explorer, right-click on project HelloWorld, and select J2ME | Create package or J2ME | Create Obfuscated Package.
- A directory HelloWorld/deployed should have been created, containing the files HelloWorld.jad and HelloWorld.jar.