0

任何人,请帮助我。我在 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
}
});
}
4

1 回答 1

1

您的外部尝试没有匹配的捕获。而且您似乎有一个没有开头的错误右括号。

在你修复了这两件事之后,我建议你很好地格式化你的代码并仔细检查你所有的大括号是否正确匹配。

另外我想问一下为什么你在你的 ArrayList 构造函数后面放了一个括号块?如果它确实编译(我不确定),我看不出有什么好处。

于 2013-05-25T03:37:01.877 回答