我已经构建了一个 jar 文件并尝试在 j2me 应用程序中使用它。我已将 jar 包含在构建路径中并导入了所需的类。但是当我运行我的 j2me 应用程序时,我在尝试实例化 jar 中存在的类的行中遇到 NoClassDefFound 错误。
我可以在 java 项目中实例化 jar 的类,但不能在 j2me 中实例化。
以下是错误日志:
警告 - MMA - C:/Builds/jme-sdk/javacall-javame-sdk-305/implementation/share/jsr135_mmapi/ju_mmconfig.c 第 801 行:大写:缺少可选设置: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() 生命周期:事件为 JAVACALL_LIFECYCLE_MIDLET_SHUTDOWN 状态为 JAVACALL_OK
测试应用程序(j2me 应用程序):
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 文件主类:
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;
}
}
位置画布类:
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;
}
错误日志:
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)
任何帮助,将不胜感激。