Question

I have build a jar file and trying to use it in j2me application. I have included the jar in the build path and imported the required classes as well. But when I run my j2me application I am getting NoClassDefFound Error in the line where I am trying to instantiate the class which is present in the jar.

I can instantiate the classes of the jar in the java project but not in j2me.

Below is the error log:

WARNING - MMA - C:/Builds/jme-sdk/javacall-javame-sdk-305/implementation/share/jsr135_mmapi/ju_mmconfig.c line 801: caps: optional settings missing: SuspendBehavior java.lang.NoClassDefFoundError: com/canvasm/ida/gps/LocationUpdater - com.test.ida.HelloIDA.(HelloIDA.java:11) - java.lang.Class.newInstance(), bci=0 - com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46 - com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66 - com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17 - com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27 - com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52 - com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8 - com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161 - com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26 javacall_lifecycle_state_changed() lifecycle: event is JAVACALL_LIFECYCLE_MIDLET_SHUTDOWN status is JAVACALL_OK

TestApp(j2me app):

import com.test.gps.LocationUpdater;

public class Hello extends MIDlet {

public Hello() {
    LocationUpdater loc = new LocationUpdater();
    System.out.println("Loc updater object :"+loc.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 {


}

}

JAR file main class:

public class LocationUpdater {

private boolean isUpdateSuccess = false;


public static void main(String[] args){


}

public boolean updateLocation(final String serverUrl, final String userMSISDN) throws LocationException{
    AppConstants.url = serverUrl;
    AppConstants.msisdn = userMSISDN;

    LocationCanvas loc = new LocationCanvas();
    isUpdateSuccess = loc.getLocation(serverUrl, userMSISDN);

    return isUpdateSuccess;
}

}

LocationCanvas class:

 public class LocationCanvas {

private Location location;
private LocationProvider locationProvider;
private Coordinates coordinates;
private Criteria criteria;
private Timer tm;
private double lat, lon;
private String posturl;
private boolean status,updateStatus;

public LocationCanvas() {


}

public boolean getLocation(String url, String msisdn) {

    tm = new Timer();

    criteria = new Criteria();
    criteria.setHorizontalAccuracy(500);

    try {

        locationProvider = LocationProvider.getInstance(criteria);

        if (locationProvider != null) {

            tm.wait(4000);

            try {
                location = locationProvider.getLocation(2000);
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }

            coordinates = (Coordinates)location.getQualifiedCoordinates();
            if (coordinates != null) {
                // Use coordinate information
                lat = coordinates.getLatitude();
                lon = coordinates.getLongitude();

                System.out.println("Latitude :"+lat);
                System.out.println("Longitude :"+lon);
            }

            posturl = url + "?IMEI=" + msisdn
                    + "&positioningtype=" + "gps" + "&locationdata=" + lat
                    + "," + lon;


        }else{
            //return false.. cos location provider is null
            updateStatus = false;
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return updateStatus;

}

error log:

Exception in thread "main" java.lang.NoClassDefFoundError:
    javax/microedition/location/Coordinates
at com.canvasm.ida.gps.LocationUpdater.updateLocation(LocationUpdater.java:17)
at com.test.HelloTest.main(HelloTest.java:10)
Caused by: java.lang.ClassNotFoundException: javax.microedition.location.Coordinates
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

Any help would be appreciated.

Était-ce utile?

La solution 2

Finally able to solve the issue.
The problem was not in the code. It was due to the compilation issue.

First of all To solve the NoClassDefFoundError , I had to right click on the project and in the build path-> order and export -> check the jar that you have added.

Later while running I faced classFormatError 56.

The jar file which was created, was compiled using 1.6v.
And the j2me application was getting compiled with 1.3v.

I had to recompile my library project with 1.3v and create a jar out of it and used it in the j2me application.

Here is the link to guide: Build a Project from the Command Line - Java ME SDK

Autres conseils

It specifies that class file present at compile time is not found at run time.Check for build time and run time classpaths .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top