×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    48

    JSR Support and MIDlets

    Hi. I'm writing an application that uses a Location API for some features.
    I want to run the MIDlet on all the mobile phones. In phones where Location API are supported the user can use these features, otherwise it cannot use them, but all the other features must be enabled.
    The problem is that i tried to run it on Nokia N70 that doesn' t support Location API and the MIDlet doesn't run at all, while on Sony Ericsson K608i (that doesn't support Location API too) it runs fine and i can query the phone with System.getProperty("javax.microedition.location").

    On the Sony it returns NULL and so i can disable the feature that uses Location API.

    Now i would like to know why on the Sony i can do that while, on the N70, i can't ever run my application??

    What's the normal behaviour?The Sony's one or the Nokia's one??

    Please help me.
    Thank u

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: JSR Support and MIDlets

    What kind of MIDlet-permissions are you requesting in the JAD file?

    Hartti

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: JSR Support and MIDlets

    How do you reference location API classes? You may need to use absolute references instead of import statement, if you use it, so that classloader will not try to load them.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: JSR Support and MIDlets

    I tried with the "location" permission and also without it..but it's the same.

    I tried also with absolute references instead of import statements but it doesn't work anyway..maybe cause a class of the application implements the LocationListener interface.
    Anyway i can't understand why on the sony ericsson it works even if Location API are not supported.

    I don't want to have two versions of the same MIDlet. I would like do detect the Location API support dynamically on runtime but I don't know how to achieve that. Any idea??

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: JSR Support and MIDlets

    As already said in another thread

    1) trying to load JSR-specific class is safe and *reliable* way to detect JSR support presence in a device

    2) of course having you main class implementing JSR-specific interface is not good - put the JSR-specific code into a separate class (no imports there still advisable), detect JSR-support presence (eg in the main class), and call the helper class only if it's ok

    try {
    Class clazz = Class.forName("javax.microedition.location.LocationProvider");
    jsr179 = true;
    } catch (ClassNotFoundException e) {
    }

    ...

    if (jsr179) {
    "use helper class in some way"
    }

    ...

    Helper class for JSR-specific code:
    Code:
    public class Jsr179Stuff {
        private javax.microedition.location.LocationProvider impl;
    
        public Jsr179LocationProvider() {
            impl = javax.microedition.location.LocationProvider.getInstance(null);
            impl.setLocationListener(new StuffListener, ...);
            ...
        }
    
        private class StuffListener implements implements javax.microedition.location.LocationListener {
            // fullfill contract here
        }
    }
    Last edited by hnipak; 2006-10-17 at 14:20.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: JSR Support and MIDlets

    I'm sorry but i think i've not understood.

    I actually do all the Location API stuff in a separate class that implements the LocationListener interface. This is not the MIDlet class, or a class that it's loaded in the midlet constructor or something.
    I instantiate the location class only if i detect that the Location API are supported but it doesn't work anyway.

    My MIDlet has a method like:

    checkSupported(){
    s=System.getProperty("javax.microedition.location");
    if(s==null)
    supported=false;
    else
    supported=true;
    }

    and a SEPARATE class Localizer:

    public class Localizer implements javax.microedition.location.LocationListener{

    location stuff;

    }

    and only if supported is true i do something like:

    if(supported){
    Localizer l=new Localizer();
    l.localize();
    }


    Is that what u meant?

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: JSR Support and MIDlets

    ...............................................
    Last edited by Paranoid_Android; 2006-10-18 at 17:52.

  8. #8
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: JSR Support and MIDlets

    But your MIDlet class references the Localizer class that implements LocationListener interface that is not available in N70, so I pressume the linker fails to resolve it and therefore the app fails to start.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    48

    Re: JSR Support and MIDlets

    Ok. But so i can't understand how to do it in a different way.
    Localizer needs to implement LocationListener....

    I tried to remove all the imports referred to Location API and Localizer class but i get the same problem on the N70...

  10. #10
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: JSR Support and MIDlets

    Indeed, some class has to implement LocationListener interface, but it cannot be the "top-level" class referenced by your midlet class, because when your app is launched, the classloader will try to resolve all classes that the midlet class "uses", including Localizer class which unfortunately implements an interface that is not available in most phones.

    Try to change the Localizer class like this:
    Code:
    // ...
    // no location API imports
    // ...
    public class Localizer {
        private javax.microedition.location.LocationProvider impl;
    
        public localize() {
            impl = javax.microedition.location.LocationProvider.getInstance(null);
            impl.setLocationListener(new StuffListener, ...);
            ...
        }
    
        private class StuffListener implements implements javax.microedition.location.LocationListener {
            // fullfill interface contract here
        }
    }

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Please have a look at JSR-248 chapter 8.1.

  12. #12
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: JSR Support and MIDlets

    Yes, that is the right thing. Thank you.

  13. #13
    Registered User
    Join Date
    May 2006
    Posts
    48

    Thumbs up Re: JSR Support and MIDlets

    Yea! It works. I wonder why on the Sony Ericsson it worked also without this "workaround".

    Thank u for the help!

Similar Threads

  1. NoClassDefFoundError: javax/bluetooth/DiscoveryListener
    By eitand in forum Bluetooth Technology
    Replies: 5
    Last Post: 2006-07-25, 14:30
  2. 6600 supporting signed midlets?
    By steffi1 in forum Mobile Java General
    Replies: 1
    Last Post: 2004-11-02, 06:52
  3. Urgent! -- Midlets -- Please!!
    By earamsey in forum Mobile Java General
    Replies: 1
    Last Post: 2004-09-08, 06:00
  4. Will Nokia support 100% MIDP 2.0???
    By gicio in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2003-08-18, 11:23
  5. SMS and Nokia phones
    By rudolphous in forum Mobile Java General
    Replies: 4
    Last Post: 2003-08-04, 08:50

Posting Permissions

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