ObjectInputStream抛出ClassNotFoundException

时间:2017-01-13 05:37:53

标签: android classnotfoundexception objectinputstream

我是Java和Android语言的初学者。我尝试使用eclipse将名为Bus的类序列化为Bus.ser,然后尝试使用ObjectInputStream在Android工作室中打开/反序列化Bus.ser,但它会抛出ClassNotFoundException。我已经在android studio中导入了Bus类,但异常仍然存在

这是读取Bus.ser

的类
package com.example.hafizi.octranspo;

public class Reader implements Serializable{
    private static final long serialVersionUID = 21L;
    private static Activity originActivity = null;
    public Reader(Activity activity) {
        originActivity = activity;
    }

    public Object run(String filename) {
        Object data = null;
        try {
            InputStream fis = originActivity.getResources().getAssets().open(filename);
            ObjectInputStream ois = new ObjectInputStream(fis);
            data = ois.readObject();
            ois.close();
            System.out.println("Read completed");

        } catch (Exception e) {
            System.out.println("Error to read the file : " + filename);
            System.out.println(e);
        }
        return data;
    }
}

0 个答案:

没有答案