使用我的代码,这行由IDE强调为红色......为什么?
提前感谢大家!
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);
}
答案 0 :(得分:1)
你有这条线:
return json.toString();
在红色线之前,这意味着永远不会到达相关的线。