此代码在Java运行时上正常工作。
public static void main(String[] args) {
// TODO Auto-generated method stub
extendedList array=new extendedList();//extendedList:class extendedList extends ArrayList<XXX> implements Serializable
//....unimportant code...
FileOutputStream out;
ObjectOutputStream oout;
try {
out=new FileOutputStream("Data.dat");
oout=new ObjectOutputStream(out);
oout.writeObject(array);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileInputStream fin;
ObjectInputStream ofin;
try {
fin=new FileInputStream("Data.dat");
ofin=new ObjectInputStream(fin);
extendedList ret=(extendedList) ofin.readObject();
for(int i=0;i<ret.size();i++)
System.out.print(ret.get(i).getnum()+":"+ret.get(i).getename()+":"+ret.get(i).getfname()+"\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是当我想在android.it中读取Data.dat时会抛出ClassNotFoundException。这有什么问题?
ObjectInputStream对象;
InputStream input;
try {
Log.d("adapter","befor Open");
input=assets.open("Data.dat");
Log.d("adapter","after Open");
object= new ObjectInputStream(input);
Array=(extendedList) object.readObject();
//........hidden code
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("adapter","IOException has detected");
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
Log.d("adapter","ClassNotFoundException has detected");
e.printStackTrace();
}
当我用FileInputStream替换InputStream并强制转换asset.open(&#34; Data.dat&#34;)。当调试器到达该行时。未找到源。