在try语句中执行toast语句时遇到错误。这是我的代码。目前以这种方式发表了一个toast声明(评论格式)。我可以知道推杆的正确方法是什么?感谢。
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs2));
HttpResponse response = httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response1 = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response1);
if(response1.contains("Duplicated")){
finish();
}
//{Toast.makeText(getBaseContext(), "You have registered this event before.", Toast.LENGTH_LONG).show();}
{
jsonResult = inputStreamToString(
response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
答案 0 :(得分:0)
感谢帮助人员。我自己修好了。
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs2));
HttpResponse response = httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response1 = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response1);
if(response1.contains("Duplicated")){
Register.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(Register.this, "You have registered this event before.", Toast.LENGTH_LONG).show();
}
});
finish();
}
jsonResult = inputStreamToString(
response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}