我想要的是什么: 在我的android项目中使用包含我所有模型类的jar文件(在我分离模型的webservice中重用)。我是android新手所以我想我错过了什么?在android中使用它时,是否有必要以不同的方式导出我的类?
我得到了什么:
`11-15 12:26:14.082: E/Trace(1776): error opening trace file: No such file or directory (2)
11-15 12:26:14.152: E/dalvikvm(1776): Could not find class 'ww.entities.model.User', referenced from method com.example.weightwatchersapp.MainActivity.onCreate
11-15 12:26:14.172: W/dalvikvm(1776): VFY: unable to resolve new-instance 812 (Lww/entities/model/User;) in Lcom/example/weightwatchersapp/MainActivity;
11-15 12:26:14.172: D/dalvikvm(1776): VFY: replacing opcode 0x22 at 0x000a
11-15 12:26:14.182: D/dalvikvm(1776): DexOpt: unable to opt direct call 0x1499 at 0x0c in Lcom/example/weightwatchersapp/MainActivity;.onCreate
11-15 12:26:14.212: W/System.err(1776): TEST
11-15 12:26:14.262: D/AndroidRuntime(1776): Shutting down VM
11-15 12:26:14.262: W/dalvikvm(1776): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
11-15 12:26:14.292: E/AndroidRuntime(1776): FATAL EXCEPTION: main
11-15 12:26:14.292: E/AndroidRuntime(1776): java.lang.NoClassDefFoundError: ww.entities.model.User
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.example.weightwatchersapp.MainActivity.onCreate(MainActivity.java:17)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.Activity.performCreate(Activity.java:5104)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.os.Looper.loop(Looper.java:137)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-15 12:26:14.292: E/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 12:26:14.292: E/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:511)
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-15 12:26:14.292: E/AndroidRuntime(1776): at dalvik.system.NativeStart.main(Native Method)`
我做了什么: 为了生成它我使用了一个简单的java项目(不是库项目或类似的东西,并将其导出为jar。 我可以在我的webservice java项目中使用相同的库而没有任何问题。
我尝试了什么: 1.使用自动生成的类MainActivity并添加以下代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.err.println("TEST");// TODO: error here
User user = new User();
user.setDailyPoints(13);
}
我试图遵循许多线程,处理类似的问题,但不知何故,似乎我错过了重点。 (不需要说我是新手Android并需要一个全面的答案,对于noobies吧?^^)
修改
I´m using ormlite with my models so i.e. my class User looks like:
public class User implements Serializable {
private static final long serialVersionUID = -2057474913370787753L;
@DatabaseField(generatedId = true)
private long id;
@DatabaseField(canBeNull = false, unique = true)
private String username;
@DatabaseField
private String password;
@DatabaseField
private String email;
@DatabaseField
private String forename;
@DatabaseField
private String surname;
@DatabaseField
private Date birthday;
@DatabaseField
private String sex;
@DatabaseField
private double height;
@DatabaseField
private int dailyPoints;
@DatabaseField
private int weeklyPoints;
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private OnlineUserFlags onlineUserFlags;
@DatabaseField
private boolean showProfileOnline;
public User() {
}
public User(String username, String password, String email, String forename, String surname, Date birthday, String sex, double height, int dailyPoints, int weeklyPoints, OnlineUserFlags onlineUserFlags, boolean showProfileOnline) {
super();
this.username = username;
this.password = password;
this.email = email;
this.forename = forename;
this.surname = surname;
this.birthday = birthday;
this.sex = sex;
this.height = height;
this.dailyPoints = dailyPoints;
this.weeklyPoints = weeklyPoints;
this.onlineUserFlags = onlineUserFlags;
this.showProfileOnline = showProfileOnline;
}
@Override
public int hashCode() {
//generated hascode method
}
@Override
public boolean equals(Object obj) {
//generated equals method
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
//...getters/setters
}
答案 0 :(得分:0)
最简单的方法(至少在SDK工具0.22.2.1中)是不导出jar,而是将你的ww-entities
项目添加为你的android项目的依赖项(Build Path>项目)。
然后,您需要确保在订单和导出标签中查看ww-entities
。