我搜索了所有通過相關的線程,我沒有成功,歡迎任何相關的答案。從sdcard讀取json文件返回 - 空指針異常
我有一個JSON數據作爲.json
文件的SD卡.NewFolder
文件夾內, 我想讀文件中的數據和分析,找到時間戳和要重寫,如果時間戳是不同的。
以下是我使用的代碼,我得到aBuffer
中的數據和jdata_fromfile
中的值,但我在解析時得到了nullPointerException。
myFile = new File(Environment.getExternalStorageDirectory() + "/.NewFolder/" +str.get(i));
if(myFile.exists())
{
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null)
{
aBuffer += aDataRow;
}
myReader.close();
jdata_fromfile = new JSONObject(aBuffer);
String timestamp_fromfile = jdata_fromfile.getString(str_timestamp.get(i));
timestamp_val_fromfile.add(timestamp_fromfile);
}
else
{
myFile.createNewFile();
writedate_tofile(value_json.toString());
timestamp_val_fromfile.add("xxx");
}
而且還在於,當我打開記事本文件,它是所有中只顯示數據的一部分一行,當我複製到http://jsonformatter.curiousconcept.com
我得到的全部數據和一個有效的json。 我可以在記事本中看到剩餘的數據 - ctrl + end並按下回車鍵。
這是爲什麼,我在哪裏出錯?
這是我的錯誤 - 登錄
02-13 18:44:52.109: E/aBuffer value(7134): is {"Status":{"Itemlist":[{"x - Drinks":{"Details":[{"type":"","image":"","price":"","name":"Minerals"},{"type":"","image":"","price":"","name":"Milk Shakes"},{"type":"","image":"","price":"","name":"Milk"},{"type":"","image":"","price":"","name":"Mineral Water"},{"type":"","image":"","price":"","name":"Hot Beverages"},{"type":"","image":"","price":"","name":"Chocolate Muffin and Ice Cream"}, ........................................................................{"type":"","image":"","price":"","name":"Blu
02-13 18:44:52.189: E/jdata_fromfile value(7134): is {"x Time_stamp":"2013-02-12 12:30:00","Status":{"Itemlist":[{"x - Sides":{"Details":[{"type":"","image":"","name":"Onion Rings (6)","price":""},{"type":"","image":"","name":"Sausage Portion (Minimum 2 per portion)","price":""},.................................................................................................................... ,"x - Burgers":{"Details":[{"type":"","image":"","name":"x 5oz Burger","price":""},{"type":"","image":"","name":"x 5oz Cheese Burger","price":""},{"type":"","image":"","name":"x 5oz with Bacon and Cheese","price":""},{"type":"","imag
02-13 18:44:52.189: E/Reading from internal file - Exception e(7134): java.lang.NullPointerException
在此先感謝。
在哪一行你會得到NullPointerException?只需發佈堆棧跟蹤。 – svennergr 2013-02-13 13:00:36
我正在使用一個try-catch上面的代碼中,我也得到:02-13 18:33:15.909:從內部文件E /閱讀 - 異常E(6632):顯示java.lang.NullPointerException – VIGNESH 2013-02-13 13:07:26
張貼整個堆棧跟蹤你得到。 – svennergr 2013-02-13 13:08:31