Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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
为什么可以';在Java中的try块之后是否打印到控制台?_Java_Android_Try Catch - Fatal编程技术网

为什么可以';在Java中的try块之后是否打印到控制台?

为什么可以';在Java中的try块之后是否打印到控制台?,java,android,try-catch,Java,Android,Try Catch,我在Android应用程序中有以下代码: public static HttpResponse dbPost(String handlerUrl, List<NameValuePair> postData) { HttpClient httpclient = new DefaultHttpClient(); String postUrl = constants.postUrl(); HttpPost httppost = new HttpPost(post

我在Android应用程序中有以下代码:

public static HttpResponse dbPost(String handlerUrl, List<NameValuePair> postData) {

    HttpClient httpclient = new DefaultHttpClient();
    String postUrl = constants.postUrl(); 
    HttpPost httppost = new HttpPost(postUrl);
    HttpResponse response = null;
    System.out.print("Catch 0");

    try {
        httppost.setEntity(new UrlEncodedFormEntity(postData));
        response = httpclient.execute(httppost);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print("Catch 1");

    return response;

}
公共静态HttpResponse dbPost(字符串handlerUrl,列表postData){
HttpClient HttpClient=新的DefaultHttpClient();
字符串postrl=常量。postrl();
HttpPost HttpPost=新的HttpPost(姿态);
HttpResponse响应=null;
系统输出打印(“捕获0”);
试一试{
setEntity(新的UrlEncodedFormEntity(postData));
response=httpclient.execute(httppost);
}捕获(不支持的编码异常e){
e、 printStackTrace();
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
系统输出打印(“Catch 1”);
返回响应;
}
我有一个按钮可以调用这个块。如果我按下按钮,控制台将打印“Catch 0”(但不是“Catch 1”)。如果我再次按下按钮(同一实例),控制台将打印“Catch1Catch0”。有什么问题吗


我对Java有点陌生,所以请容忍我。

您使用的是
print
而不是
println
您使用的是
print
而不是
println
,因为您使用的是
print
,所以您需要调用它

System.out.print("Catch 1");
System.out.flush();
PrintStream
的默认行为是仅在写入换行符时刷新。(此行为记录在中。)

如果使用
printLn
而不是
print
,则流将自动刷新。否则,您需要显式刷新输出流。

您需要调用,因为您正在使用
print

System.out.print("Catch 1");
System.out.flush();
PrintStream
的默认行为是仅在写入换行符时刷新。(此行为记录在中。)


如果使用
printLn
而不是
print
,则流将自动刷新。否则,您需要显式刷新输出流。

是否捕获错误并打印堆栈跟踪?可能在堆栈跟踪后丢失了它?是否引发了任何异常?没有错误。尝试了下面列出的println,这是我的问题。谢谢是否捕获错误并打印堆栈跟踪?可能在堆栈跟踪后丢失了它?是否引发了任何异常?没有错误。尝试了下面列出的println,这是我的问题。谢谢那又怎么样?应该提供更多的信息,而不是写精确的解决方案。那又怎样?应该提供更多信息,而不是编写精确的解决方案。