You stated the problem yourself: the class has a different package name in your Android app. Why are you doing that? You should use exactly the same jar in both apps.
How to serializable from java application and de-serializable on android?
-
28-06-2023 - |
سؤال
I'm a newbie from Android, and I'm developing an application on Android. The app need use a class to de-serializable and get data. This is class:
package fu.sna2014.smartnavigation.utility;
import java.io.Serializable;
public class StreetObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = 437865663147928104L;
private String id;
private String name;
private byte[] sound;
public StreetObject(String id, String name, byte[] sound) {
this.id = id;
this.name = name;
this.sound = sound;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getSound() {
return sound;
}
public void setSound(byte[] sound) {
this.sound = sound;
}
}
My problem is this class is serializabled from another Java application with package name:
package snaTool;
import java.io.Serializable;
/**
*
* @author conghits
*/
public class StreetObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = 437865663147928104L;
private String id;
private String name;
private byte[] sound;
//private transient List<File> unInterestingLongLongList;
public StreetObject(String id, String name, byte[] sound) {
this.id = id;
this.name = name;
this.sound = sound;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getSound() {
return sound;
}
public void setSound(byte[] sound) {
this.sound = sound;
}
}
And when I de-serializable it make ClassNotFoundException snaTool.StreetObject. I have searched many topics and get a solution as make .jar for StreetObject from Java application and import to Andoird as libs but when I import, Eclipse( for coding Android) not found the .jar as libs, other word I can call class from the .jar on Eclipse. Anyone help me known what wrong here? Thanks so much and sorry about my English writing :)
المحلول
لا تنتمي إلى StackOverflow