Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 序列化问题_Android_Serialization - Fatal编程技术网

Android 序列化问题

Android 序列化问题,android,serialization,Android,Serialization,我在序列化对象时遇到了一些问题 我想我遗漏了一些东西,因为我的应用程序没有像应该的那样保存.dat 让我们展示一些代码: 加载.dat文件 public void gravar(ObjectOutputStream out) throws IOException { out.writeObject(lista); out.writeObject(cadeiras); out.writeObject(notas); out.close(); }

我在序列化对象时遇到了一些问题

我想我遗漏了一些东西,因为我的应用程序没有像应该的那样保存.dat

让我们展示一些代码:

加载.dat文件

public void gravar(ObjectOutputStream out) throws IOException {
      out.writeObject(lista);
      out.writeObject(cadeiras);
      out.writeObject(notas);
      out.close();
  }
public void carregar(ObjectInputStream in) throws IOException, ClassNotFoundException {
     lista=(ArrayList<String>) in.readObject();
     cadeiras=(ArrayList<String>) in.readObject();
     notas= (ArrayList<String>) in.readObject();
      in.close();
  }
保存.dat文件

public void gravar(ObjectOutputStream out) throws IOException {
      out.writeObject(lista);
      out.writeObject(cadeiras);
      out.writeObject(notas);
      out.close();
  }
public void carregar(ObjectInputStream in) throws IOException, ClassNotFoundException {
     lista=(ArrayList<String>) in.readObject();
     cadeiras=(ArrayList<String>) in.readObject();
     notas= (ArrayList<String>) in.readObject();
      in.close();
  }
fich这是:

private static String fich = "gravar.dat";
我错过了什么?为了获得更好的帮助,我将代码放在这里


提前谢谢

您应该将整个路径而不仅仅是文件名传递给
FileOutputStream

如果那样做不起作用,试试看

new FileOutputStream(new File(fich));

解决方法是,而不是

out = new ObjectOutputStream(new FileOutputStream(fich));
粘贴这个

out = new ObjectOutputStream(this.openFileOutput(fich, Context.CONTEXT_IGNORE_SECURITY));

输出也一样。

我知道答案,我会在可能的时候(+/-7小时)发布答案。