MIDLet 1.0 vs MIDLet 2.0

Hi All,
I migrated my code from Midlet 1.0 to Midlet 2.0. and found that all my ItemStateListener does not response to my ChoiceGroup selectoin change. Is this a new feature of Midlet 2.0 or something I missed here? I tried this on WSDD, Java WTK and even in Blackberry IDE with exactly the same result. I appreciate if somebosy can help.
Regards,
Yongli

Hi,
The Item argument in 'itemStateChanged(..)' should never be 'null', otherwise it's not possible to 'know' which item has been changed... I always let each Form implement their own ItemStateListener and I have never had problems with that Item argument. I successfully receive the event and am able to anticipate on a certain user action. Could it be that there's something wrong inside the MIDP2.0 reference implementation that you are using for testing your MIDlet? I've experienced quite some differences between MIDP2.0 compliant implementations. I'm not using the Sun WTK reference implementation.
MIDP1.0 is pretty old and thus very stable: you can notice that when trying several MIDP1.0 compliant emulation environments. MIDP2.0 is still quite new and not all reference implementations are fully functional and bug free.
About the ChoiceGroup Item: note that (MIDP2.0) ItemStateChanged events are only fired when the user has scrolled from a certain Item to another Item or when the user has selected (by pressing the 'select' command) an item inside the ChoiceGroup. Scroll events inside the ChoiceGroup cannot be detected by an application.
I hope that answers your question!
Jasper

Similar Messages

  • How to create an instance of midlet with in a midlet

    Hi all,
    I have 5 midlets in the same project (midlet suite). I need one of the midlets (login midlet) to start and when login is verified i want to display list of the remaining midlets which can be launched as per user's chioce.
    My query is, how can i create an instance of the other midlet within the login midlet after login is verified.
    Any response is highly appreciated.
    Birhanu

    You can't do that! You don;t need all those midlets anyway if you only have one application. You'll just have to put the needed code in a non Midlet class.

  • Automatic removing Midlet suite by another Midlet without user intervention

    I would like to use a Midlet to remove another Midlet which is already installed on the device.
    Could I do this? Are there any methods for doing this?
    Please help me!
    Thank you in advance.

    That's a different matter. The second MIDlet is launched by the Application Manager at the scheduled time, not by the MIDlet that books the PushRegistry alarm. And there's no way you can possibly
    go back to my midlet again.Apart from which, many devices will ask the user's permission before launching an application scheduled by PushRegistry, so even the first part of your requirement can't be guaranteed to be seamless.
    Why do you think you need this? There may be an easier solution, like using related classes with only one MIDlet.
    db

  • Chiamare una midlet dentro un altra midlet---calling a midlet into a midlet

    i'm new to j2me...
    i created a midlet and i need to call another midlet by pressing (select) a button or sth like that
    how can i do it????
    thanks in advance...

    Looks like your classes that extend MIDlet are doing too much. For a very simple application, it may be OK to keep everything together in one class that extends MIDlet, but you've crossed that boundary of simplicity.
    One application, one MIDlet. And a MIDlet doesn't display StringItems, a Form does. You get a Display reference from the Display class using Display.getDisplay(MIDlet midlet) and show the Form by display.setCurrent(form). And the StringItems are added to the Form, not to the MIDlet.
    I don't see where Threads come in the picture.
    i have a midlet1 that does sth, another midlet2 that does sth else Please take the trouble to type out words in full. On a forum with international membership there are many members whose first language is not English and who may find it difficult to fathom extreme abbreviations. And don't forget that programming is an exercise in precision, and sloppy language finds no place.
    db

  • How to clear the cookie in midlet before quite the midlet?anyone?pls

    i am fresh in J2ME . Can anyone teach me on how to clear the cookie in midlet before i quit from it?
    I designed an application that require login and use session(cookie) management, i need to clear the cookie before or during i quit the midlet, so that the user will need to login again after quit from midlet. Can anyone pls assist me? i need it urgently!

    I designed an application that require login and use session(cookie) management,How did you implement the cookies. This isn't a built-in part of J2ME. You have to implement it yourself (saving the cookie and resending it in future requests), so only you can know how to delete it.
    shmoove

  • How to change the application (MIDlet) input language at MIDlet run-time?

    Hi,
    I am working on a Messaging (SMS) J2ME MIDlet where it is required to change the input language for a TextField/Area at run-time.
    For example if default handset language is set to Chinese, during MIDlet execution time the textfield language (locale) should be changed to Arabic/Spanish/French. Here I understand that provided the required languages are supported on handset, one can change them from handset settings.
    Can anyone help me out with changing the microedition.locale to zh_CN from en_US?
    Thanks

    Dear Ted,
    I want to change DataSource, it means the report will be load and change connection at run time (using CRJ SDK) and i want to change the SCHEMA.Tablename in CommandTable in report.
    I also use the parameter to do it, but it can not be at run time, just correct when designing.
    Could you please help me on this. You can post the code if any.
    Thanks,
    Nha

  • Midlet gets null values from servlet

    hey,
    based on one of the source code examples on the java.sun.com website i made a midlet/servlet application. the midlet is sending a product id to the servlet, the servlet queries the database and shows the productinformation, the midlet reads the servlet output and displays it on his midlet form
    when i invoke the servlet in my browser: http://localhost:8080/Magazijn/query?product=1 then everything works fine (i see: Product Name : Deur). when the midlet is invoking the servlet i see Product Name : null
    after hours of searching the only thing i could come up with is that the servlet isn't passing the string retrieved from the resultset to the midlet
    the strange thing is that when i papss a normal string, for instance:
    String test = "test";
    out.println(test);
    that he shows this correct both in my browser and midlet
    when i do this:
    prodName = resutl.getString("name");
    out.println(prodName);
    i see "Deur" in my browser, but i see "null" in my midlet
    anyone can help me?
    here's the servlet source:
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.Date;
    public class Magazijn extends HttpServlet {
    public void doGet(HttpServletRequest request,
              HttpServletResponse response)
                        throws IOException, ServletException {
              doPost(request,response);
    public void doPost(HttpServletRequest request,
              HttpServletResponse response)
                        throws IOException, ServletException {
         String url="jdbc:mysql://localhost/test?user=root&password=root";
         Connection con = null;
         Statement stmt;
         ResultSet rs;
         String query;
         int prodId;
         String prodNaam;
         String prodPlaats;
         String prodAantal;
         response.setContentType("text/plain");
         PrintWriter out = response.getWriter();
         BufferedReader br = request.getReader();
         String buf = br.readLine();
         try {
                   //laden van de mysql driver
                   Class.forName("com.mysql.jdbc.Driver");
                   //maken van connectie met database
                   con = DriverManager.getConnection (url, "root", "root");     
                   //aanmaken van statement object
                   stmt = con.createStatement();
                   //nakijken welke naam we zoeken van product
                   String prod = request.getParameter("product");
                   //uitvoeren van query en die opvangen in een resultset
                   query = "SELECT * from onderdelen where id="+prod;
                   ResultSet result = stmt.executeQuery(query);
                   result.next();
                   prodId = result.getInt("id");
                   prodNaam = result.getString("naam");
                   prodPlaats = result.getString("plaats");
                   prodAantal = result.getString("aantal");
              out.println(new Date());
              out.println("");
                   out.println("Product ID: "+prodId);
                   out.println("Productnaam: "+prodNaam);
                   out.println("Plaats: "+prodPlaats);
                   out.println("Aantal: "+prodAantal);
              catch(ClassNotFoundException e) {
                   out.println("Could not load database driver: " + e.getMessage());
              catch(SQLException e) {
                   out.println("SQLException caught: " + e.getMessage());
              finally {
                   //sluiten database connectie
                   try {
                        if (con != null) con.close();
                   catch (SQLException e) {}
    here's the midlet source:
    import javax.microedition.rms.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import java.io.*;
    import java.util.Vector;
    public class MagazijnMidlet extends MIDlet implements CommandListener {
    Display display = null;
    List menu = null;
    TextBox input = null;
    String prodid = null;
    String url = "http://localhost:8080/Magazijn/query";
    static final Command backCommand = new Command("Terug", Command.BACK, 0);
    static final Command submitCommand = new Command("Verstuur", Command.OK, 2);
    static final Command exitCommand = new Command("Afsluiten", Command.STOP, 3);
    String currentMenu = null;
    public MagazijnMidlet() { }
    public void startApp() throws MIDletStateChangeException {
    display = Display.getDisplay(this);
    menu = new List("Maak uw keuze", Choice.IMPLICIT);
    menu.append("Opvragen product gegevens", null);
    menu.addCommand(exitCommand);
    menu.setCommandListener(this);
    mainMenu();
    public void pauseApp() { }
    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    void mainMenu() {
    display.setCurrent(menu);
    //Vraag om productnummer op te geven
    public void askProdid() {
    input = new TextBox("Geef Productnummer:","", 5, TextField.ANY);
    input.addCommand(submitCommand);
    input.addCommand(backCommand);
    input.setCommandListener(this);
    input.setString("");
    display.setCurrent(input);
    //Maken connectie midlet + verwerking
    void invokeServlet(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("IF-Modified-Since",
         "20 Jan 2001 16:19:14 GMT");
    c.setRequestProperty("User-Agent",
         "Profile/MIDP-1.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    // send request to the servlet.
    os = c.openOutputStream();
    String str = "product="+prodid;
    byte postmsg[] = str.getBytes();
    System.out.println("Length: "+str.getBytes());
    for(int i=0;i<postmsg.length;i++) {
    os.write(postmsg);
    // or you can easily do:
    //os.write(("product="+prodid).getBytes());
    os.flush();
    // receive response and display it in a textbox.
    is = c.openInputStream();
    int ch;
    while((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.print((char)ch);
    Form formProdGeg = new Form ("Gegevens product");
    StringItem infoItem = new StringItem("",b.toString());
    formProdGeg.append (infoItem);
    formProdGeg.addCommand (backCommand);
    formProdGeg.setCommandListener (this);
    display.setCurrent (formProdGeg);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    // event handler
    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("Afsluiten")) {
    destroyApp(true);
    } else if (label.equals("Terug")) {
    mainMenu();
    } else if (label.equals("Verstuur")) {
    prodid = input.getString();
    try {
    invokeServlet(url);
    }catch(IOException e) {}
    } else {
    askProdid();
    tia
    lee

    Hi,
    first for some efficeincy, in your place your connection to the database in the init() method so you can have on instance of the connection.
    in your midlet place the ui initialization in its constructor
    ok, Why dont you try the query in the url
    i.e http://localhost:8080/Magazijn/query=";
    then as you input the product id without setting requests
    c = (HttpConnection)Connector.open(url+productid);
    i think it will work properly
    tell me what happens with you

  • Parameters from midlet to servlet

    Hi all,
    i have been trying to pass values from MIDlet (setRequestProperty(); ) and to servlet (request.getParameter();).
    but when i tried to print out the value, it just contained NULL value.
    I had a look at the java forum website, there were plenty of same problems and no one got right.
    I'll really appreciate it if anyone fixes this for me.
    ---------------------MIDLET-----------------------------------------------------------------------------
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.*;
    import java.util.*;
    import org.kxml.*;
    import org.kxml.parser.*;
    public class MbankMIDlet  extends MIDlet implements CommandListener {
      private Display display;
      private Form loginForm = new Form("Login");
      private Form mainForm = new Form("MobileBank");
      private String loguserID;
      private String logpass;
      private String mSession;
      private StringItem stringItem = new StringItem(null,"");
      private TextField userIDTextField = new TextField("User ID", "", 8, TextField.NUMERIC);
      private TextField passwordTextField = new TextField("Password", "", 12, TextField.PASSWORD);
      static final Command loginCommand = new Command("Login", Command.OK, 1);
      static final Command exitCommand = new Command("Exit", Command.STOP, 1);
      static final Command backCommand = new Command("Back",Command.BACK, 1);
      public MbankMIDlet() {
        mainForm.append(stringItem);
        mainForm.addCommand(exitCommand);
        mainForm.addCommand(backCommand);
        mainForm.setCommandListener(this);
      public void startApp() throws MIDletStateChangeException {
        display = Display.getDisplay(this);
        loginForm.append(userIDTextField);
        loginForm.append(passwordTextField);
        loginForm.addCommand(loginCommand);
        loginForm.addCommand(exitCommand);
        loginForm.addCommand(backCommand);
        loginForm.setCommandListener(this);
        display.setCurrent(loginForm);
      public void destroyApp(boolean unconditional) {
        notifyDestroyed();
      public void mainMenu() {
        display.setCurrent(loginForm);
      public void pauseApp() {
        display = null;
        loginForm = null;
        mainForm = null;
        stringItem = null;
        userIDTextField = null;
        passwordTextField = null;
      public void commandAction(Command c, Displayable d) {
        String label = c.getLabel();
        if (label.equals("Exit")) {
          destroyApp(true);
           mSession = null;
        } else if (label.equals("Login")) {
          login();
        } else if (label.equals("Back")){
          mainMenu();
      private void login() {
        loguserID = userIDTextField.getString();
        logpass = passwordTextField.getString();
        Form waitForm = new Form("Waiting...");
        display.setCurrent(waitForm);
        Thread t = new Thread() {
          public void run() {
            connect();
        t.start();
      private void connect() {
        HttpConnection hc = null;
        InputStream in = null;
        OutputStream os = null;
        String url = getAppProperty("MbankMIDlet.URL");
        try {
          hc = (HttpConnection)Connector.open(url);
          hc.setRequestMethod(HttpConnection.GET);
          hc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0" );
          hc.setRequestProperty("Content-Language", "en-US" );
          hc.setRequestProperty("Accept", "text/plain");
          hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
          hc.setRequestProperty("Connection","close");
          hc.setRequestProperty("loguserID", loguserID);
          hc.setRequestProperty("logpass", logpass);
          os = hc.openOutputStream();
          os.close();
    //      os.flush();  //tried close() and flush() but none of them worked.
          if (mSession != null) {
              hc.setRequestProperty("Cookie", mSession);
          // Read the session ID from a cookie in the response headers.
          String cookie = hc.getHeaderField("Set-cookie");
          if (cookie != null) {
              int semicolon = cookie.indexOf(';');
              mSession = cookie.substring(0, semicolon);
          in = hc.openInputStream();
          int rc = hc.getResponseCode();
          if( rc == HttpConnection.HTTP_OK ) { //HTTP_OK equals 200
            System.out.println("HttpConnection OK");
            StringBuffer xmlBuffer = new StringBuffer();
            String xmlString = null;
            int ch;
            while ( ( ch = in.read() ) != -1 )
              xmlBuffer.append( ( char )ch );
            xmlString = xmlBuffer.toString();
            stringItem.setText(xmlString);
          else if (rc == HttpConnection.HTTP_UNAUTHORIZED){//HTTP_UNAUTHORIZED equals 401
            System.out.println("HttpConnection Unauthorized");
            int contentLength = (int)hc.getLength();
            byte[] raw = new byte[contentLength];
            int length = in.read(raw);
            String s = new String(raw,0,length);
            stringItem.setText(s);
          in.close();
          hc.close();
        catch (IOException ioe) {
          stringItem.setText(ioe.toString());
        finally {
          display.setCurrent(mainForm);
    }---------------SERVLET----------------------------------------------------------------------------
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.io.*;
    public class LoginServlet extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              HttpSession session = request.getSession();
              response.setContentType("text/plain");
              PrintWriter out = response.getWriter();
              String userID, password, userRole = null;
              try {
                                  userID = (String)request.getParameter("loguserID");
                  password = (String)request.getParameter("logpass");
                  System.out.println(userID); // "Null printed"              System.out.println(password);  // "Null printed"
              catch (Exception e) {
                   //If anything goes wrong, print the Exception message
                  e.printStackTrace(out);
    }Thanks.

    getParameter() can't parse the input stream well if there is any issues in the sent content. this is true, with varying mobile phone http impl.
    You would find the content at servlet, by using request.getInputStream() and reading the entire content.
    Here is the sample code:
    public static String readMobileData(final HttpServletRequest aRequest) throws Exception
         String lData = null;
         Enumeration params = aRequest.getParameterNames();
         while (params.hasMoreElements())
         //from real Nokia 6600 Mobile the request is sent as param, though
         //it is post
         String lName = params.nextElement().toString();
         lData = aRequest.getParameter(lName);
         System.out.println("\nParameter:" + lName + "=" + lData);
         if (lData == null)
         //in emulator the data is coming as inputstream
         ServletInputStream in = aRequest.getInputStream();
         DataInputStream dIn = new DataInputStream(in);
         lData = dIn.readUTF();
         lData = lData.substring(lData.indexOf("=") + 1);
         System.out.println("Stream Request:\n" + lData);
         return lData;
    Regards,
    Raja Nagendra Kumar,
    C.T.O,
    When Teja is Tasked, the Job Gets Done
    www.tejasoft.com

  • [Request For Help] How To Send Email Midlet Using Secure Socket ?

    Hello, this is the first time i ask for help to forum.sun.com.
    i try to make secure connection for send email from MIDlet. Maybe you can check to my code :
    EmailMidlet.java
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.lcdui.;
    public class EmailMidlet extends MIDlet implements CommandListener{
    Display display = null;
    // email form fields
    TextField toField = null;
    TextField subjectField = null;
    TextField msgField = null;
    Form form;
    static final Command sendCommand = new Command("send", Command.OK, 2);
    static final Command clearCommand = new Command("clear", Command.STOP, 3);
    String to;
    String subject;
    String msg;
    public EmailMidlet() {
    display = Display.getDisplay(this);
    form = new Form("Compose Message");
    toField = new TextField("To:", "", 50, TextField.EMAILADDR);
    subjectField = new TextField("Subject:", "", 15, TextField.ANY);
    msgField = new TextField("MsgBody:", "", 90, TextField.ANY);
    public void startApp() throws MIDletStateChangeException {
    form.append(toField);
    form.append(subjectField);
    form.append(msgField);
    form.addCommand(clearCommand);
    form.addCommand(sendCommand);
    form.setCommandListener(this);
    display.setCurrent(form);
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("clear")) {
    destroyApp(true);
    } else if (label.equals("send")) {
    to = toField.getString();
    subject = subjectField.getString();
    msg = msgField.getString();
    EmailClient client = new EmailClient(this,"[email protected]", to, subject, msg);
    client.start();
    }and EmailClient.java
    import javax.microedition.io.;
    import javax.microedition.lcdui.;
    import java.io.;
    import java.util.Date;
    public class EmailClient implements Runnable {
    private EmailMidlet parent;
    private Display display;
    private Form f;
    private StringItem si;
    private SecureConnection sc; //SSL
    private InputStream is;
    private OutputStream os;
    private String smtpServerAddress = "smtp.gmail.com"; //SSL
    String from;
    String to;
    String subject;
    String msg;
    public EmailClient(EmailMidlet m, String from, String to, String subject, String msg) {
    parent = m;
    this.from = from;
    this.to = to;
    this.subject = subject;
    this.msg = msg;
    display = Display.getDisplay(parent);
    f = new Form("Email Client");
    si = new StringItem("Response:" , " ");
    f.append(si);
    display.setCurrent(f);
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    try {
    //SSL
    sc = (SecureConnection)
    Connector.open("ssl://"smtpServerAddress":465"); //smtp with SSL port 465
    sc.setSocketOption(SocketConnection.LINGER, 5);
    is = sc.openInputStream();
    os = sc.openOutputStream();
    os.write(("HELO there" "\r\n").getBytes());
    os.write(("EHLO" "\r\n").getBytes());
    os.write(("auth login" "\r\n").getBytes());
    os.write(("dHVnYXNha2hpci50cmlhZGl0eWFAZ21haWwuY29t" "\r\n").getBytes());
    os.write(("dGEuZW1haWxjbGllbnQ=" "\r\n").getBytes());
    os.write(("MAIL FROM:<">\r\n").getBytes());
    os.write(("RCPT TO:<">\r\n").getBytes());
    os.write("DATA\r\n".getBytes());
    // stamp the msg with date
    os.write(("Date: " new Date() "\r\n").getBytes());
    os.write(("From: "+from"\r\n").getBytes());
    os.write(("To: "to"\r\n").getBytes());
    os.write(("Subject: "subject"\r\n").getBytes());
    os.write((msg+"\r\n").getBytes()); // message body
    os.write(".\r\n".getBytes());
    os.write("QUIT\r\n".getBytes());
    StringBuffer sb = new StringBuffer();
    int ch = 0;
    while((ch = is.read()) != -1) {
    sb.append((char) ch);
    si.setText("SMTP server response - " + sb.toString());
    } catch(IOException e) {
    e.printStackTrace();
    Alert a = new Alert
    ("TimeClient", "Cannot connect to SMTP server. Ping the server to make sure it is running...", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    } finally {
    try {
    if(is != null) {
    is.close();
    if(os != null) {
    os.close();
    if(sc != null) {
    sc.close();
    } catch(IOException e) {
    e.printStackTrace();
    public void commandAction(Command c, Displayable s) {
    if (c == Alert.DISMISS_COMMAND) {
    parent.notifyDestroyed();
    parent.destroyApp(true);
    } When I try to debug project from netbeans, i found this error :
    Starting emulator in debug server mode on port 2668
    Connecting to 127.0.0.1 on port 2800
    nbdebug:
    Waiting for debugger on port 2668
    Waiting for KVM...
    Running with storage root temp.SonyEricsson_JP8_128x160_Emu10
    KdpDebugTask connecting to debugger 1 ..
    Running with locale: Indonesian_Indonesia.1252
    Connected to KVM
    Connection received.
    Attached JPDA debugger to localhost:2668
    java.io.IOException: error 10054 during TCP read +
    at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(Protocol.java:299)+
    at com.sun.midp.io.BufferedConnectionAdapter.readBytes(BufferedConnectionAdapter.java:99)+
    at com.sun.midp.io.BaseInputStream.read(ConnectionBaseAdapter.java:582)+
    at com.sun.midp.ssl.Record.rdRec(+41)+
    at com.sun.midp.ssl.Record.rdRec(+5)+
    at com.sun.midp.ssl.In.refill(+18)+
    at com.sun.midp.ssl.In.read(+29)+
    at EmailClient.run(EmailClient.java:74)+
    Execution completed.
    5145824 bytecodes executed
    9258 thread switches
    1762 classes in the system (including system classes)
    0 dynamic objects allocated (0 bytes)
    0 garbage collections (0 bytes collected)
    debug:
    BUILD SUCCESSFUL (total time: 4 minutes 34 seconds)
    Regard
    Littlebro

    Don't multipost and don't use the browser's back button to edit your posts as that creates multiple postings. I've removed the other thread you started with the same questio.
    Also, don't post to long dead threads. I've blocked your post and locked the thread you resurrected.
    db

  • How to create two instances of a midlet

    Hi!
    I've programmed a MIDlet that can organize a tournament (save player datas, show rankings...). Right now it can only manage one tournament at a time but now I'd like to be able to manage two simultaneous. I designed the midlet like the famous "Smarticket"-Midlet: a "wrapper" midlet class and a controller class that handles the events. For those of you who dont know the Smartticket example here is my subclass of MIDlet:
    public class MagicTOMIDlet extends javax.microedition.midlet.MIDlet {
        private TOUIController controller;
        public void startApp() {
            new Thread() {
                public void run() {
                    controller = new TOUIController(MagicTOMIDlet.this);
                    controller.init(); // setCurrents() to MainMenu - the entry point of the program
            }.start();
        public void pauseApp() {
        public void destroyApp(boolean unconditional) {
    }The problem is: How can I create two midlets so that I can switch between the 2 tournaments to enter for example new Data (resuts...)? The tournaments don't affect each other, they just have to run simultaneously. My phone is a Nokia 3510i and it can't just run 2 copies of the MIDlet.
    I had two solutions in mind but both didn't work:
    1.) Declare 2 controller classes controller1 and controller2 and a switch Command, that can switch between both. After starting the midlet ask the user if he wants to organize one or two tournaments.
    Here is the code for the MIDlet subclass:
    public class MagicTOMIDlet extends MIDlet implements CommandListener {
        public TOUIController controller1, controller2;
        private List list;
        private Command okCommand;
        private Command exitCommand;
        private Display display;
        private Thread t1, t2;
        private MagicTOMIDlet midlet;
        public void startApp() {
            display = Display.getDisplay(this);
            list = new List("Choose # of Drafts", List.IMPLICIT);
            okCommand = new Command("OK", Command.OK, 1);
            exitCommand = new Command("Exit", Command.EXIT, 5);
            list.append("1 Draft", null);
            list.append("2 Drafts", null);
            list.addCommand(okCommand);
            list.addCommand(exitCommand);
            list.setCommandListener(this);
            display.setCurrent(list);
        public void commandAction(Command command, Displayable displayable) {
            if ((command == okCommand) || (command == List.SELECT_COMMAND)) {
                String label = list.getString(list.getSelectedIndex());
                if (label.equals("1 Draft")) {
                    t1 =  new Thread() {
                        public void run() {
                            midlet.controller1 = new TOUIController(midlet, TOUIController.DRAFT_SINGLE);
                            midlet.controller1.init();
                    t1.start();
                } else if (label.equals("2 Drafts")) {
                    t1 = new Thread() {
                        public void run() {
                            midlet.controller1 = new TOUIController(midlet, TOUIController.DRAFT_1);
                            midlet.controller1.init();
                    t2 = new Thread() {
                        public void run() {
                            midlet.controller2 = new TOUIController(midlet, TOUIController.DRAFT_2);
                            midlet.controller2.init();
                    t2.start();
                    t1.start();
            } else if (command == exitCommand) {
                destroyApp(true);
        }And here parts of the controller class:
    public class TOUIController implements CommandListener {
        public TOUIController(MagicTOMIDlet midlet, byte id) {
            this.midlet = midlet;
            this.draftId = id; // DRAFT_1 = 1, DRAFT_2 = 2, DRAFT_SINGLE = 0
            if (id == DRAFT_SINGLE) {
                singleDraft = true;
            } else if (id == DRAFT_1) {
                otherDraftId = DRAFT_2;
                singleDraft = false;
            } else if (id == DRAFT_2) {
                otherDraftId = DRAFT_1;
                singleDraft = false;
        public void commandAction(Command command, Displayable displayable) {
          else if (command == switchCommand) {
                if (draftId == DRAFT_1) {
                    setCurrent(midlet.controller2.display.getCurrent());
                } else if (draftId == DRAFT_2) {
                    setCurrent(midlet.controller1.display.getCurrent());
        }Somehow it doesn't work. If I try to Switch I land in the MainMenu of the same Tournament (here called: draft).
    My 2nd solution would be to declare two midlets in MagicTOMIDlet and to pass both midlets to the controller class:
    public class MagicTOMIDlet extends MIDlet implements CommandListener {
        public TOUIController controller;
        private List list;
        private Command okCommand;
        private Command exitCommand;
        private Display display;
        private Thread t1, t2;
        public MagicTOMIDlet midlet1;
        public MagicTOMIDlet midlet2;
        public MagicTOMIDlet() {
            midlet1 = this;
            midlet2 = this;
        public void startApp() {
            // as above
        public void commandAction(Command command, Displayable displayable) {
            if ((command == okCommand) || (command == List.SELECT_COMMAND)) {
                String label = list.getString(list.getSelectedIndex());
                if (label.equals("1 Draft")) {
                    t1 =  new Thread() {
                        public void run() {
                            midlet1.controller = new TOUIController(midlet1, TOUIController.DRAFT_SINGLE);
                            midlet1.controller.init();
                    t1.start();
                } else if (label.equals("2 Drafts")) {
                    t1 = new Thread() {
                        public void run() {
                            midlet1.controller = new TOUIController(midlet1, midlet2, TOUIController.DRAFT_1);
                            midlet1.controller.init();
                    t2 = new Thread() {
                        public void run() {
                            midlet2.controller = new TOUIController(midlet2, midlet1, TOUIController.DRAFT_2);
                            midlet2.controller.init();
                    t2.start();
                    t1.start();
    public class TOUIController implements CommandListener {
        public TOUIController(MagicTOMIDlet midlet, MagicTOMIDlet otherMidlet, byte id) {
            this.midlet = midlet;
            this.otherMidlet = otherMidlet;
            this.draftId = id;
            if (id == DRAFT_SINGLE) {
                singleDraft = true;
            } else if (id == DRAFT_1) {
                otherDraftId = DRAFT_2;
                singleDraft = false;
            } else if (id == DRAFT_2) {
                otherDraftId = DRAFT_1;
                singleDraft = false;
        public void commandAction(Command command, Displayable displayable) {
            } else if (command == switchCommand) {
                setCurrent(otherMidlet.controller.display.getCurrent());
    }It same the same wrong behaviour as my first solution.
    I'm tankful for any advise or solution you might give me!
    Marko

    The first way should be correct, but what do these
    lines:
    setCurrent(midlet.controller2.display.getCurrent());
    setCurrent(midlet.controller1.display.getCurrent());do?Sorry, I didn't want to make the post too long...
    public void setCurrent(Displayable displayable) {
            display.setCurrent(displayable);
        }If you are sure that my 1st solution should work I'll try to find the error.
    Thanks!
    Marko

  • Error in running MIDlet

    Hi, all
    I have a problem around MIDlet.
    Here, the MIDlet source code :
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import java.io.*;
    public class BolaMidlet extends Form implements CommandListener
    +{     +
    private Display display;
    private static final Command cmExit = new Command("Keluar", Command.EXIT, 1);
    private static final Command cmSubmit = new Command("Login", Command.OK, 1);
    private BolaMidlet midlet;
    private TextField tfUsername;
    private TextField tfMajor;
    private String result;
    public BolaMidlet(BolaMidlet midlet, Display display)
    +{+
    super("BolaMidlet");
    this.midlet = midlet;
    this.display = display;
    tfUsername = new TextField("Username", "", 20, TextField.ANY);
    tfMajor = new TextField("Major", "", 20, TextField.ANY);
    append(tfUsername);
    append(tfMajor);
    addCommand(cmExit);
    addCommand(cmSubmit);
    setCommandListener(this);
    +}+
    public void startApp()
    +{+
    display.setCurrent(this);
    +}+
    public void pauseApp()
    +{+
    display.setCurrent(null);
    +}+
    public void destroyApp(boolean unconditional)
    +{+
    +}+
    public void exitMIDlet()
    +{+
    destroyApp(false);          
    +}     +
    public void commandAction(Command c, Displayable s)
    +{+
    if(c == cmExit)
    +{+
    midlet.exitMIDlet();
    +}+
    else if(c == cmSubmit)
    +{+
    try
    +{+
    submit(tfUsername.getString(), tfMajor.getString());
    +}catch(Exception e)+
    +{+
    e.printStackTrace();
    +}+
    +}          +
    +}+
    public void submit(String user, String major)
    throws IOException
    +{+
    String url = "http://localhost:8080/hello/sayhello?user=user&pass=major";
    HttpConnection hc = null;
    StringBuffer sb = null;
    InputStream is = null;
    try
    +{+
    hc = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
    hc.setRequestMethod(HttpConnection.GET);
    hc.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.1");
    hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    if(hc.getResponseCode() == HttpConnection.HTTP_OK)
    +{+
    sb = new StringBuffer();
    int ch;
    is = hc.openInputStream();
    while((ch = is.read()) != -1)
    sb.append((char)ch);
    +}+
    else
    +{+
    System.out.println("Network error");
    +}     +
    +}catch(IOException e)+
    +{+
    e.printStackTrace();
    if(hc != null)
    hc.close();
    if(sb != null)
    result = sb.toString();
    if(is != null)
    is.close();
    +}finally+
    +{+
    if(is != null)                    
    is.close();                    
    if(sb != null)               
    result = sb.toString();                    
    if(hc != null)                    
    hc.close();                    
    +}+
    +}+
    when I compiled it, there was no problem.
    But, when I launched it on the emulator
    there was an error in WTK console like this :
    Unable to create MIDlet BolaMidlet
    java.lang.IllegalAccessException
    at com.sun.midp.midlet.MIDletState.createMIDlet(34)+
    at com.sun.midp.midlet.Selector.run(22)+
    and then the emulator said : BolaMidlet, BolaMidlet exception : java.lang.IllegalAccessException
    can someone help me to solve this ?
    I really need help for this one.
    Thank You,
    Best Regards,
    CHi
    Edited by: ichiwan on Sep 30, 2007 11:23 AM

    {color:#000080}The code you have posted is for a class that extends Form, not MIDlet.
    To post code, use code tags --{color} [code]CODE[/code] {color:#000080}is displayed as CODEPlease do not try to format parts of your code as bold or italic as that reduces the readability still more.
    db{color}

  • Unable To Create MIDlet Null

    hi all!
    i am trying to run a simple midlet code and am egtting the error:
    Unable To Create MIDlet Null
    java.lang.NullPointerException
         at com.sun.midp.midlet.MIDletState.createMIDlet(+14)
         at com.sun.midp.midlet.Selector.run(+22)
    I have tried to find out the solution but all my efforts have been in vain!
    anybody who can help me please reply to my query as soon as possible!
    your guidance will be appreciated!
    The code is as follows:
    package example.MethodTimes;
    import javax.microedition.midlet.*;
    * An example MIDlet runs a simple timing test
    * When it is started by the application management software it will
    * create a separate thread to do the test.
    * When it finishes it will notify the application management software
    * it is done.
    * Refer to the startApp, pauseApp, and destroyApp
    * methods so see how it handles each requested transition.
    public class MethodTimes extends MIDlet implements Runnable {     
    // The state for the timing thread.
    Thread thread;
    * Start creates the thread to do the timing.
    * It should return immediately to keep the dispatcher
    * from hanging.
    public void startApp() {     
    thread = new Thread(this);
    thread.start();
    * Pause signals the thread to stop by clearing the thread field.
    * If stopped before done with the iterations it will
    * be restarted from scratch later.
    public void pauseApp() {     
    thread = null;
    * Destroy must cleanup everything. The thread is signaled
    * to stop and no result is produced.
    public void destroyApp(boolean unconditional) {     
    thread = null;
         public void exitApp() {     
    destroyApp(true);
    * Run the timing test, measure how long it takes to
    * call a empty method 1000 times.
    * Terminate early if the current thread is no longer
    * the thread from the
    public void run() {     
    Thread curr = Thread.currentThread(); // Remember which thread is current
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000000 && thread == curr; i++) {     
    empty();
    long end = System.currentTimeMillis();
    // Check if timing was aborted, if so just exit
    // The rest of the application has already become quiescent.
    if (thread != curr) {     
    return;
    long millis = end - start;
    // Reporting the elapsed time is outside the scope of this example.
    // All done cleanup and quit
    // destroyApp(true);
    //notifyDestroyed();
              exitApp();
    * An Empty method.
    void empty() {     
    Thanks!!

    that is because the other projects created a package of its own. Thats no problem and not required for execution.
    You have to do
    1) create in your project's src directory a subdirectory called "examples" (if you want to use the package)
    2) in this subdir (./src/examples/) you have to put the MethodTimes.java file which contains the code from above with the "package examples;" statement.
    3) run the WTKs build and afterwards the run
    This should work. If not, be plz more precisely on whats not working.
    And the WTK 2.1 should be no problem at all since I used it too.
    hth
    Kay

  • How to create midlet file in j2se project ?

    Hi All,
    I am new in j2me. My main aim is Send the data mobile to Pc and Vice versa.
    I am using windows xp, Nokia E50 , netbeans 6.1 IDE.
    My requirement is , I want set Pc as server and Mobile is client,
    now i want to create 2 project or I can manage single class,
    In Netbeans Pc server program developed by j2se and Mobile client is Mobility application.
    It is possible to both are created at a same project ? .
    I want to created the midlet class is created on j2se project and while run my midlet from j2se project midlet was run
    on WTK Emulator.
    Please any one tell me, my requirements are possible, if yes then how to implement both are same project,
    Thanks is advance,
    With Regards,
    Ganesh kumar

    Hi Martin,
    > you can add a data-source-aliases.xml file to your
    > META-INF folder
    > so what is the name of the Default datasource?
    See http://help.sap.com/saphelp_nw04/helpdata/en/c3/4f7770b21b9f459cb13424296726b1/frameset.htm - you can generically use a variable.
    > is this applicable to EP projects?
    I won't expect this (as a portal project isn't a J2EE application itself but part of another).
    Anyhow, the datasources (and with them their alias within the J2EE engine) are managed via VisualAdmin, see http://help.sap.com/saphelp_nw04/helpdata/en/11/4963a6cf52ad429b3b3b65e003f2d1/frameset.htm
    Hope it helps
    Detlev
    PS: Please consider to reward points if answers are helpful. Thanks in advance!

  • Communication between MIDlets within the MIDlet suite.

    Hi Friends,
    I'm using WTK 2.2. I'm planning to have two MIDlets within the same MIDlet suite.
    I had two MIDlet files but after creating the Jar package , In the display screen, Only one MIDlet is displayed for launching.
    Please guide me the steps. If there is a local variable int i; then, how I do check the value of the variable between the different MIDlets?
    Please guide me on the steps .
    Thanks,
    Ravi.

    Here's the source code:
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;
    public class A extends MIDlet
         public int i=10;
         public A()
         protected void startApp()
         protected void pauseApp()
         protected void destroyApp(boolean unconditional)
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;
    public class B extends MIDlet
         public B()
         protected void startApp()
              A a=new A();
              a.i=10;
              System.out.println(a.i); //throws SecurityException at this line.
         protected void pauseApp()
         protected void destroyApp(boolean unconditional)
    }

  • Problem in executing MIDlet on Actual Device

    Below is the program i got from net, this is executing fine in the emulator but when I ported the application to actual device i.e. Nokia 7610, data was not fetched from the given URL, neither i got any exception nor error.
    I have WAP connection enabled on my mobile and also I was able to browse the same URL from the default browser that was there in the mobile.
    J2ME: The Complete Reference
    James Keogh
    Publisher: McGraw-Hill
    ISBN 0072227109
    // jad file (Please verify the jar size first)
    MIDlet-Name: httpconnection
    MIDlet-Version: 1.0
    MIDlet-Vendor: MyCompany
    MIDlet-Jar-URL: httpconnection.jar
    MIDlet-1: httpconnection, , httpconnection
    MicroEdition-Configuration: CLDC-1.0
    MicroEdition-Profile: MIDP-1.0
    MIDlet-JAR-SIZE: 100
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import java.io.*;
    public class httpconnection extends MIDlet implements CommandListener {
    private Command exit, start;
    private Display display;
    private Form form;
    public httpconnection ()
    display = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 1);
    start = new Command("Start", Command.OK, 1);
    form = new Form("Http Con");
    form.addCommand(exit);
    form.addCommand(start);
    form.setCommandListener(this);
    public void startApp()
    display.setCurrent(form);
    public void pauseApp()
    public void destroyApp(boolean unconditional)
    public void commandAction(Command command, Displayable displayable)
    if (command == exit)
    form=null;
    display.setCurrent(null);
    display=null;
    destroyApp(false);
    else if (command == start)
    HttpConnection connection = null;
    InputStream inputstream = null;
    try
    connection = (HttpConnection) Connector.open("http://www.someURL.com");
    //HTTP Request
    connection.setRequestMethod(HttpConnection.GET);
    connection.setRequestProperty("Content-Type","//text plain");
    connection.setRequestProperty("Connection", "close");
    // HTTP Response
    System.out.println("Status Line Code: " + connection.getResponseCode());
    System.out.println("Status Line Message: " + connection.getResponseMessage());
    if (connection.getResponseCode() == HttpConnection.HTTP_OK)
    System.out.println(
    connection.getHeaderField(0)+ " " + connection.getHeaderFieldKey(0));
    System.out.println(
    "Header Field Date: " + connection.getHeaderField("date"));
    String str;
    inputstream = connection.openInputStream();
    int length = (int) connection.getLength();
    if (length != -1)
    byte incomingData[] = new byte[length];
    inputstream.read(incomingData);
    str = new String(incomingData);
    else
    ByteArrayOutputStream bytestream =
    new ByteArrayOutputStream();
    int ch;
    while ((ch = inputstream.read()) != -1)
    bytestream.write(ch);
    str = new String(bytestream.toByteArray());
    bytestream.close();
    form.append(str);
    System.out.println(str);
    connection.close();
    catch(IOException error)
    System.out.println("Caught IOException: " + error.toString());
    finally
    if (inputstream!= null)
    try
    inputstream.close();
    catch( Exception error)
    /*log error*/ }
    if (connection != null)
    try
    connection.close();
    catch( Exception error)
    /*log error*/
    Please help me out what are the things I have to do to run this MIDlet on my Nokia 7610.
    Thanks in advance.

    You ever find an answer? I have an LG VX5200 phone which is supposed to support Java. But aside from downloading Java apps from other sites I'm trying to figure out which folder on the phone's filesystem you place the file. With BitPIM and QPST you can view the phone's filesystem. But as yet to find either a folder that works or combination of settings to get it to show up on the phone list of apps.
    I had hoped that maybe someone had downloaded a game from a site and then looked at the phone to see where and how it's stored. I can't from where I'm at.
    Michael

Maybe you are looking for

  • Mid 2010 MacBook Pro 15in i7 keeps crashing

    This problem has been going on for a long time now where my Mid 2010 MacBook Pro 15in w/ i7 processer keeps crashing at random times. No data is lost but it just keeps shutting down and restarting. I was thinking it may be the logic board or motherbo

  • Why can't i open a powerpoint deck without it asking me to 'open using a web application'?

    Can anyone tell me how to open a powerpoint deck on my mac--each time I click on the attachment it says, "Open as Web Page"?

  • Need architecture guide to deploy OSB & OBPM with SOA?

    Hi , Is there architecture guide available for OSB + OBMP with SOA? Thanks & Regards, Noman

  • PDF error/Blurred Image

    Hi guys, from time to time we do some pdf with the same mistake. A blured image and the rest is fine. I am attaching a sample. http://www.pixentral.com/show.php?picture=1UZrPlmekntsWkrwDReogBP6FyAsbh We work with InDesing, save as Postscript and then

  • Port mapping for outside cameras

    When I go into my Airport Extreme Airport Utility and look at the Network options, it appears that I have ports 80/9000/18004 open.  But the cameras are not working and when I go to canyouseemenow.org it says that the ports are NOT open. Any suggesti