【发布时间】:2012-12-25 21:50:18
【问题描述】:
我正在尝试让应用程序将一些 Json 数据保存在本地文件中(在 sdcard 上)..
第一次运行时,我只需要将 json-data 保存在一个文件中...
然后返回“applications_arr”(不是来自文件,而是来自 JsonReader)
查看holde asyncTask-class here:
还有ApplicationsModel.class(实现 Parcelable)
amFile = new File(this.activity.getFilesDir()+"/applications"+UUID.randomUUID()+".json");
gson = new GsonBuilder().create();
reader = new JsonReader(new BufferedReader(new InputStreamReader(new URL("http://software-center.ubuntu.com/api/2.0/applications/any/ubuntu/any/any/").openConnection().getInputStream())));
reader.beginArray();
//save am-json-data on sdcard
FileWriter fw = new FileWriter(amFile.getAbsoluteFile());
fw.write(gson.toJson(reader, ApplicationsModel.class));
fw.close();
//create am-arraylist to use now.. amFile is other use
while (reader.hasNext()) {
ApplicationsModel model = gson.fromJson(reader, ApplicationsModel.class);
applications_arr.add(model);
}
reader.endArray();
reader.close();
看起来错误是:
fw.write(gson.toJson(reader, ApplicationsModel.class));
我的 Logcat 看起来像 this。
【问题讨论】:
-
错误是什么,您在 logcat 中是否有任何内容,或者您根本没有得到预期的结果?
-
Yes logcat say FATAL EXCEPTION: AsyncTask #2.. 我已经用 logcat-drop 更新了这个问题。
标签: java android io gson java-io