我的应用程序从Internet" myJavaObject"下载文件,将其存储在内部存储上,如果下载成功,则转到以下活动。此活动抛出异常:" ClassNotFoundException:AJavaObject",但我不明白为什么。下载的文件包含一个ArrayList
谁可以帮助我?
为什么我在第二次使用时遇到错误" AJavaObject而不是第一个?
public class RetrieveMyJavaObject extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
//NOT HERE!!!!!!!!!!!!!
ArrayList<AJavaObject> deserialized = new ArrayList<AJavaObject>();
try{
FileInputStream inputFileStream = openFileInput("myJavaObjects");
ObjectInputStream objectInputStream = new ObjectInputStream(inputFileStream);
//NEXT LINE THROWS EXCEPTION!
deserialized = (ArrayList<AJavaObject>) objectInputStream.readObject();
objectInputStream.close();
inputFileStream.close();
}
catch (Exception e){Log.e("Error in openFiles",""+e);}
}
class AJavaObject implements Serializable {
private String firstString;
private String secondString;
private static final long serialVersionUID = 1L;
public AJavaObject(String s1, String s2){
this.firstString=s1; this.secondString=s2;
}
public String getFirstString(){ return this.firstString; }
public String getSecondString(){ return this.secondString; }
}
}
这是错误日志:
02-03 18:05:15.283 6607-6607/com.testing.anapp W/System.err﹕ java.lang.ClassNotFoundException: AJavaObject
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.Class.classForName(Native Method)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.Class.forName(Class.java:251)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2265)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1784)
02-03 18:05:15.361 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1985)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1942)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.util.ArrayList.readObject(ArrayList.java:661)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
02-03 18:05:15.369 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1330)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1242)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1837)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1985)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1942)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at com.testing.anapp.RetrieveMyJavaObject.onCreate(RetrieveMyJavaObject.java:6)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5231)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5146)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
02-03 18:05:15.376 6607-6607/com.testing.anapp W/System.err﹕ Caused by: java.lang.NoClassDefFoundError: AJavaObject
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ ... 33 more
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ Caused by: java.lang.ClassNotFoundException: Didn't find class "AJavaObject" on path: DexPathList[[zip file "/data/app/com.testing.anapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.testing.anapp-1, /vendor/lib, /system/lib]]
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-03 18:05:15.384 6607-6607/com.testing.anapp W/System.err﹕ ... 33 more