在下面的代码中,我的吐司没有显示。但是,我得到错误,“RuntimeException:不能创建处理程序内部没有调用Looper.prepare()”的线程。 我试图Add_City.this
和getApplicationContext
为什么我的吐司不显示
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
JSONObject json_data = new JSONObject(result);
code=(json_data.getInt("code"));
System.out.println(code);
if(code==1)
{
Toast.makeText(Add_City.this, "Inserted Successfully",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Add_City.this, "Sorry, City Already Available",Toast.LENGTH_LONG).show();
}
Log.i("TAG", "Result Retrieved");
} catch (Exception e) {
Log.i("TAG", e.toString());
}
可能有一个例外,当你打开一个流或JSON解析器是 – phongvan
的System.out.println(代码);打印在您的控制台中。如果没有,你的执行永远不会达到那段代码。检查Log.i(“TAG”,e.toString());正在登录控制台。如果是这样,你有一个例外。解决例外,你应该得到你的敬酒。 – Tony
我该如何解决? – AndroidBoy