×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    8

    Some J2ME questions

    Hi all,
    I have a few quick problems that I'm hoping you can help with:

    Using J2ME w/NetBeans.

    I want to divide my program into multiple classes in different files. So I make a class for the File Browser part of my program but without "extends MIDlet" on it. I can invoke it from the main class and everything is fine, except for 3 things:

    1. I am waiting for the user to select a file in the File Browser. The only way I can figure out how to do this is to get the main thread to sleep every 200ms and then check if they have selected a file:
    Code:
            while(browser.getPath().equals("")) {
                try{
                    Thread.currentThread().sleep(200);
                }
                catch(InterruptedException ie){
                    ie.printStackTrace();
                }
            }
    Surely there is a better way to do it?

    2. I can't call notifyDestroyed() from the FileBrowser class, so I have to use a variable to communicate back to the main class. This works fine (it happens in the waitforfile() function below), except that at one point of the program I am in an infinite loop that I thought would be broken if notifyDestroyed() is called. Apparently if it's in this infinite loop it won't exit at all.

    Code:
    while(true)
    {
      path = waitForFile();
      playClip(path);
    }
    3. When I start up the program on the emulator it gives me two choices of MIDlet, main and FileBrowser. Main is the only valid one and the only one I want to launch. Will this happen when I deploy it on the phone?

  2. #2
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: Some J2ME questions

    I don't quite follow what you mean.

    Regarding point 2:
    never write this kind of infinite loops, instead of the true or false value, put a flag and change the value of the flag when you want to exit the application

    Regarding point 3:
    It seems you have created two midlets. If you have several midlets in your midlet suit, then you will have several choices.

    In your case, only one class should extend from MIDLet, the other one is a simple java class. To have a reference of the midlet, you can pass it in the constructor of the second class.
    :Ruben

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Some J2ME questions

    Quote Originally Posted by grasshopa View Post
    Hi all,
    I have a few quick problems that I'm hoping you can help with:

    1. I am waiting for the user to select a file in the File Browser. The only way I can figure out how to do this is to get the main thread to sleep every 200ms and then check if they have selected a file:
    Code:
            while(browser.getPath().equals("")) {
                try{
                    Thread.currentThread().sleep(200);
                }
                catch(InterruptedException ie){
                    ie.printStackTrace();
                }
            }
    Surely there is a better way to do it?

    2. I can't call notifyDestroyed() from the FileBrowser class, so I have to use a variable to communicate back to the main class. This works fine (it happens in the waitforfile() function below), except that at one point of the program I am in an infinite loop that I thought would be broken if notifyDestroyed() is called. Apparently if it's in this infinite loop it won't exit at all.

    Code:
    while(true)
    {
      path = waitForFile();
      playClip(path);
    }
    3. When I start up the program on the emulator it gives me two choices of MIDlet, main and FileBrowser. Main is the only valid one and the only one I want to launch. Will this happen when I deploy it on the phone?
    Hi,
    @ For the second point I will say to you that when you wana call to notifyDestroyed() set a boolean variable as true..and then check that variable in while() loop..One more thing is important to avoid the infinite loop. ..is that always try to take a boolean while running the infinite loop..so that if you want to break that loop then you change that variable and loop will break.

    @ About the third point if you want to have only MAIN --then just remove the second midlet..


    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Beginner J2ME questions
    By Poldie in forum Mobile Java Media (Graphics & Sounds)
    Replies: 11
    Last Post: 2010-04-02, 13:33
  2. Acessing voice channel using J2ME
    By diegomello in forum VoIP
    Replies: 1
    Last Post: 2008-10-21, 15:57
  3. J2ME SMS simple questions
    By aztroboy in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-08-20, 06:44
  4. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36
  5. need urgent guidance on j2me
    By cogni_niru in forum Mobile Java General
    Replies: 1
    Last Post: 2005-11-13, 15:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×