我已经构建了一个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
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文件主类:
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类:
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)
任何帮助都将不胜感激。
答案 0 :(得分:1)
它指定在运行时找不到编译时出现的类文件。检查构建时间和运行时类路径。
答案 1 :(得分:1)
终于能够解决问题了 问题不在代码中。这是由于汇编问题。
首先要解决NoClassDefFoundError
,我必须右键单击项目并在构建路径中 - >订单和出口 - >检查你添加的jar。
稍后在跑步时,我遇到了 classFormatError 56 。
创建的jar文件是使用 1.6v 编译的 j2me应用程序正在编译时使用 1.3v 。
我必须使用1.3v
重新编译我的库项目并从中创建一个jar并在j2me应用程序中使用它。
以下是指南的链接:Build a Project from the Command Line - Java ME SDK