-2
用我的代码,这条线被IDE强调为红色......为什么?JSON文件不起作用
感谢大家提前!
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/droidText/";
这是我的代码:
public String showResult(View v) throws IOException {
for (Planet p : plAdapter.getBox()) {
if (p.isSelected()){
result += "\n" + p.getName()+" "+p.getDistance()+"€"+"q.tà :"+p.getQuantità();
}
}
//Toast.makeText(context, result + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();
return result;*/
String result = "";
JsonObject json = new JsonObject();
for (Planet p : plAdapter.getBox()) {
if (p.isSelected()){
json.put("name",p.getName());
json.put("distance",p.getDistance());
json.put("quantity",p.getQuantità());
}
}
return json.toString();
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/droidText/";
FileWriter file=null;
try {
file = new FileWriter(path+"filename.json");
file.write(result);
}catch(IOException ie){}
finally{
file.flush();
file.close();
}
//System.out.println(result);
}
错误信息是什么? –
无法访问的语句... – ZAO
您正在返回该行之前。 –