Monday, 21 July 2008

Creating a J2ME app with EclipseME and Sony Ericsson SDK

I wanted to try out creating a little J2ME application which could be deployed onto my Sony Ericsson K850i phone. Sony do provide an SDK, and there seems to be a lot of documentation on their developer site , but there wasn't much in the way of a "Hello World" example.

So this is my example of creating a J2ME application using the EclipseME plugin.
This example should work on similar Sony Ericsson phones.


Prerequisites

You need to have the following installed before doing anything else:
First you need to download and install the Sony Ericsson SDK 2.5.0.2 for the Java(TM) ME Platform . Install it in the default location which should be "C:\SonyEricsson\JavaME_SDK_CLDC\". Keep a note of this location

Next you will need to install the EclipseME plugin to Eclipse
  1. Follow the install instructions from here.
  2. After you have restarted Eclipse ,you will need to configure EclipseME with Eclipse. Follow the instructions from here and in step 4 use the location you noted down above(i.e. C:\SonyEricsson\JavaME_SDK_CLDC\)
Now you can create a new J2ME Midlet Project. Follow the instructions from here to do this.

Now create a new Midlet class following the instructions from here and replace the template code with this:

package com.randomconsultant.test;

import java.util.Date;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MyMidlet extends MIDlet {

Alert timeAlert;

public MyMidlet() {
timeAlert = new Alert("Alert!");
timeAlert.setString(new Date().toString());

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(timeAlert);


}

}

Now you can run in debug mode in the phones emulator

You should see the date pop up for a moment in the emulator.

Now that we know we have a working app, we can try deploying it onto our phone. You have to create a package that will create a jad and jar file:


The jad and jar file will be dropped into the deployed folder within your project.

Now connect your phone via the usb cable or using bluetooth and copy the jad and jar file to somewhere on your phone.

Disconnect your phone from your pc, and open file manager on your phone ( Menu > Organizer > File Manager on my K850i) and select the jad file you copied over. Click on it and it will ask you where you would like to install the jad file (i.e. in applications or games).

Now your application can be selected from which ever menu you added it to (applications or games) and you will be able to run it!

For all my source code you can download it from here.

Leave a comment if you can't get this working or need a hand.

5 comments:

  1. i tried urer tutorial and transferred those jad and jar files to sony ericsson w700i.But when i run it from games or application i get "invalid application"

    ReplyDelete
  2. hello

    please i need guidance. on a shell to develop a knowledge-based system for an undergraduate course.

    thank you

    Emma

    ReplyDelete
  3. please help send me a shell to use while building a simple knowledge-based system . new in this field.

    thanks

    Emma

    ReplyDelete
  4. I, of course, a newcomer to this blog, but the author does not agree

    ReplyDelete
  5. Android is an operating system such as mobile devices like smart phones and tablet computers.Android is a Linux base mobile application which is providing very fastest services .This Android Incredible features get good popularity In market.Android has a large community of developers writing applications that extend the functionality of the devices.We are also providing good logic to develop more In this field.

    ReplyDelete