任何人,请帮助我。我在 try 语句中遇到错误,警告说我必须将 finally 语句放在那里,但警告仍然在那里。我已经将它复制到新页面并重试,但仍然出现相同的错误。
private void receiveMsg() {
Bundle bundle = this.getIntent().getExtras();
final String param1 = bundle.getString("keyCourseId");
final String param2 = bundle.getString("keyChatId");
final String param3 = bundle.getString("keyUserId");
final String param4 = bundle.getString("keyChatMsgsId");
// TODO Auto-generated method stub
linkurl = new Koneksi(this);
SERVER_URL = linkurl.getUrl();
SERVER_URL += "/mobile/ChatReceive.php?idc="+param1+"&idch="+param2+"&idu="+param3+"&idcm="+param4;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(SERVER_URL);
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();{
try {
//add parameter
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpRespose = httpClient.execute(httpPost);
HttpEntity httpEntity = httpRespose.getEntity();
//read content
InputStream in = httpEntity.getContent();
BufferedReader read = new BufferedReader(new InputStreamReader(in));
String content = "";
String message = "";
while((message = read.readLine())!=null){
content += message;
}
Log.d("ADBUG", "content: "+content);
//json
if(!content.equals("null")){
try {
JSONArray jArr = new JSONArray(content);
String chatname="";
String messages="";
for(int i=0;i<jArr.length();i++){
JSONObject jObj = jArr.getJSONObject(i);
String name = jObj.getString("name");
String msg = jObj.getString("msg");
chatname += name+"\n";
messages += msg+"\n";
}
messagesContainer.setTag(messages);
friendLabel.setText(chatname);
}catch (Exception e) {
showMessage(message, false);
}
} //<- in here the warning says must put finally statement but still got red mark
}
});
}