public void save(){
String tmpfile = "/mnt/sdcard/1234.txt";
KeyFrameInfo flashMotionInfoCache = new KeyFrameInfo();
try {
File f = new File(tmpfile);
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(flashMotionInfoCache);
oos.flush();
oos.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class KeyFrameInfo implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public int bBlank;
public float aca;
}在oos.writeObject(flashMotionInfoCache);会抛异常,java.io.NotSerializableException:xxx
何解?androidSerializable异常java
String tmpfile = "/mnt/sdcard/1234.txt";
KeyFrameInfo flashMotionInfoCache = new KeyFrameInfo();
try {
File f = new File(tmpfile);
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(flashMotionInfoCache);
oos.flush();
oos.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class KeyFrameInfo implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public int bBlank;
public float aca;
}在oos.writeObject(flashMotionInfoCache);会抛异常,java.io.NotSerializableException:xxx
何解?androidSerializable异常java
解决方案 »
- 问大家一个关于数据库存放本地图片路径怎么获取的问题
- apk签名之后 javascript脚本失效
- 用移动基站定位,已经获取CID和LACID怎样得到具体的地址
- 大家有没有办法实现以下效果:这里有若干条句子,要分页显示,有上一页和下一页Button
- 请问如何在真机上调试运行android中frameworks目录下的相关代码?
- 急问
- ? - TextView.setEms什么意思
- [求助]android里如何打开系统的短信编辑窗口
- android sina 微博分享 认证错误
- Android studio2.2 tools/android device monitor打开之后就开始报错,具体情况如下图,小白一只希望大神能够不吝解惑~~
- 问个imageview问题
- android.jar 源代码问题
发:
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
new ObjectOutputStream(output).writeObject(flashMotionInfoCache);
return output.toByteArray();
} catch(IOException e) {
return null;
}
收:
new ObjectInputStream(
new ByteArrayInputStream(上面返回的byte[])).readObject();
public static class KeyFrameInfo implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public int bBlank;
public float aca;
}第二种方法就是把KeyFrameInfo单独作为一个类,不要写成内部类
oos.writeObject(flashMotionInfoCache);
ObjectInputStream 与 ObjectOutputStream 类所读写的对象必须实现了 Serializable 接口。
需要注意的是:对象中的 transient 和 static 类型的成员变量也不会被读取和写入 。只要让这个类 implements Serializable 即可
就相当于一个“通行证”一样,你这个类具备了这个Serializable,就可以被 ObjectInputStream 与 ObjectOutputStream 类操作了~~~~个人理解,讲得不好勿喷~~~