我试图将EditText的ArrayLists(ArrayOne,ArrayTwo和ArrayThree)保存到内部存储。正如评论,它清楚地表明,它试图保存,但我从来没有得到另一个TOAST。任何帮助,为什么它不显示“保存完成”或任何错误,赞赏。Android内部对象存储
public void save(Context c)
{
String fileName;
Toast.makeText(this, "Attempting Save", Toast.LENGTH_SHORT).show();//THIS SHOWS
if(semester.getText().toString().length() == 0)
{
Toast.makeText(c, "Please enter a filename", Toast.LENGTH_SHORT).show();
}
else
{
fileName = "test.dat";
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try
{
fos = this.openFileOutput(fileName, Context.MODE_PRIVATE);
oos = new ObjectOutputStream(fos);
oos.writeObject(ArrayOne);
oos.writeObject(ArrayTwo);
oos.writeObject(ArrayThree);
Toast.makeText(c, "Save Completed", Toast.LENGTH_SHORT).show(); //THIS NEVER SHOWS
}
catch (FileNotFoundException e)
{
Toast.makeText(c, "Could not find " + fileName + " to save.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (oos != null)
oos.close();
if (fos != null)
fos.close();
}
catch (Exception e)
{ /* do nothing */ }
}
}
}
你好,你尝试调试?它显示“无法找到”? – PedroAGSantos
我没有尝试调试,没有任何显示“尝试保存”后。我不知道代码从哪里出发。 – Andrew
尝试调试。如果你调试它,你不需要任何其他人的帮助来解决这个问题。只是跟踪你的代码去的地方,你已经完成:) –