Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android try-catch-finally语句中出现错误_Android_Exception Handling_Try Catch - Fatal编程技术网

Android try-catch-finally语句中出现错误

Android try-catch-finally语句中出现错误,android,exception-handling,try-catch,Android,Exception Handling,Try Catch,任何人,请帮助我。我在try语句中出错,警告说我必须将finally语句放在那里,但警告仍然在那里。我已经将其复制到新页面并重试,但仍然收到相同的错误 private void receiveMsg() { Bundle bundle = this.getIntent().getExtras(); final String param1 = bundle.getString("keyCourseId"); final String param2 = bundle.getS

任何人,请帮助我。我在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
}
});
}
private void receiveMsg(){
Bundle Bundle=this.getIntent().getExtras();
最终字符串param1=bundle.getString(“keyCourseId”);
最终字符串param2=bundle.getString(“keyChatId”);
最终字符串param3=bundle.getString(“keyUserId”);
最终字符串param4=bundle.getString(“keychatmsgid”);
//TODO自动生成的方法存根
linkurl=新的Koneksi(本);
SERVER_URL=linkurl.getUrl();
SERVER_URL+=“/mobile/ChatReceive.php?idc=“+param1+”&idch=“+param2+”&idu=“+param3+”&idcm=“+param4;
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(服务器URL);
ArrayList param=新的ArrayList(){
试一试{
//添加参数
setEntity(新的UrlEncodedFormEntity(参数));
HttpResponse HttpResponse=httpClient.execute(httpPost);
HttpEntity HttpEntity=httpRespose.getEntity();
//阅读内容
InputStream in=httpEntity.getContent();
BufferedReader read=新的BufferedReader(新的InputStreamReader(in));
字符串内容=”;
字符串消息=”;
而((message=read.readLine())!=null){
内容+=消息;
}
Log.d(“ADBUG”,“内容:+内容”);
//json
如果(!content.equals(“null”)){
试一试{
JSONArray jArr=新JSONArray(内容);
字符串chatname=“”;
字符串消息=”;

对于(inti=0;i您的外部尝试没有匹配的catch。并且您似乎有一个错误的没有开口的右括号

在您修复了这两件事之后,我建议您对代码进行良好的格式化,并再次检查所有大括号是否正确匹配


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

红色标记在那里,因为您可能在平衡键(“{}”)时出现语法错误您已经添加了一个“尝试”,但没有添加“捕获”…尝试为每次“尝试”添加一个“捕获”…@Daniel,非常感谢您的帮助..是的,我有不匹配的括号…@ASP非常感谢您的帮助,我忘记在其中添加一些“捕获”:)非常感谢您的帮助,是的,我有不匹配的括号:)