IOException异常e是空 [英] IOException e is null

查看:243
本文介绍了IOException异常e是空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  异常为NULL总是

我有一个奇怪的问题,一个IOException对象,无法找到这样的一个答案。

code是这样的:

 尝试{//这是不是很重要的一部分,但也许它是与一个问题
  HTT presponse响应= client.execute(HTTPGET);
  状态行状态行= response.getStatusLine();
  INT状态code = statusLine.getStatus code();
  如果(状态code == 200){
    HttpEntity实体= response.getEntity();
    InputStream的内容= entity.getContent();
    的BufferedReader读卡器=新的BufferedReader(新InputStreamReader的(内容));
    串线;
    而((行= reader.readLine())!= NULL){
      builder.append(线);
    }
  } 其他 {
    Log.e(ParseJSON.class.toString(),无法下载文件);
  }
}赶上(IOException异常E){
        的System.out.println(我在这里的IOException异常catch子句中的);
        e.printStackTrace(); // e是空(行126)
}赶上(例外五){
        e.printStackTrace();
}
 

程序捕获 IOException异常,但它的对象(e)是。这怎么可能?

编辑:堆栈跟踪:

  09-25 19:35:59.438:我/的System.out(31732):我在这里的IOException异常catch子句中
09-25 19:36:04.377:W / dalvikvm(31732):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40020ac0)
09-25 19:36:04.447:E / AndroidRuntime(31732):致命异常:主要
09-25 19:36:04.447:E / AndroidRuntime(31732):java.lang.RuntimeException的:无法启动的活动ComponentInfo {uniwersytet.ekiosk / uniwersytet.ekiosk.EkioskActivity}:显示java.lang.NullPointerException
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.os.Handler.dispatchMessage(Handler.java:99)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.os.Looper.loop(Looper.java:123)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread.main(ActivityThread.java:4627)
09-25 19:36:04.447:E / AndroidRuntime(31732):在java.lang.reflect.Method.invokeNative(本机方法)
09-25 19:36:04.447:E / AndroidRuntime(31732):在java.lang.reflect.Method.invoke(Method.java:521)
09-25 19:36:04.447:E / AndroidRuntime(31732):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860)
09-25 19:36:04.447:E / AndroidRuntime(31732):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-25 19:36:04.447:E / AndroidRuntime(31732):在dalvik.system.NativeStart.main(本机方法)
09-25 19:36:04.447:E / AndroidRuntime(31732):由:显示java.lang.NullPointerException
09-25 19:36:04.447:E / AndroidRuntime(31732):在uniwersytet.ekiosk.EkioskActivity.onCreate(EkioskActivity.java:126)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-25 19:36:04.447:E / AndroidRuntime(31732):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-25 19:36:04.447:E / AndroidRuntime(31732):11 ...更多
 

解决方案

- 请检查响应你是从服务器获取

- 也请注意这...这 UI的工作应该是无UI线程UI线程和非UI工作,从Android的蜂巢版本成为一个规则。

- 请使用螺纹与处理程序的AsyncTask 对于这种很长一段时间采取的任务。

Possible Duplicate:
Exception is NULL always

I've got a strange problem with an IOException object and couldn't find an answer for this.

Code looks like this:

try { // This isn't very important part, but maybe it has something to do with a problem
  HttpResponse response = client.execute(httpGet);
  StatusLine statusLine = response.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  if (statusCode == 200) {
    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
    String line;
    while ((line = reader.readLine()) != null) {
      builder.append(line);
    }
  } else {
    Log.e(ParseJSON.class.toString(), "Failed to download file");
  }
} catch (IOException e) {
        System.out.println("I'm here in the IOException catch clause");
        e.printStackTrace(); // e is null (line 126)
} catch (Exception e) {
        e.printStackTrace();
}

Program catches IOException, but its object (e) is null. How is this possible?

Edit: Stack Trace:

09-25 19:35:59.438: I/System.out(31732): I'm here in the IOException catch clause
09-25 19:36:04.377: W/dalvikvm(31732): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
09-25 19:36:04.447: E/AndroidRuntime(31732): FATAL EXCEPTION: main
09-25 19:36:04.447: E/AndroidRuntime(31732): java.lang.RuntimeException: Unable to start activity ComponentInfo{uniwersytet.ekiosk/uniwersytet.ekiosk.EkioskActivity}: java.lang.NullPointerException
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.os.Looper.loop(Looper.java:123)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at java.lang.reflect.Method.invokeNative(Native Method)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at java.lang.reflect.Method.invoke(Method.java:521)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at dalvik.system.NativeStart.main(Native Method)
09-25 19:36:04.447: E/AndroidRuntime(31732): Caused by: java.lang.NullPointerException
09-25 19:36:04.447: E/AndroidRuntime(31732):    at uniwersytet.ekiosk.EkioskActivity.onCreate(EkioskActivity.java:126)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-25 19:36:04.447: E/AndroidRuntime(31732):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-25 19:36:04.447: E/AndroidRuntime(31732):    ... 11 more

解决方案

- Please check the response you are getting from the Server.

- Please also take note of it... that UI work should be on UI thread and Non-UI work on the Non-UI thread, from HoneyComb Version of Android it became a rule.

- Please use a thread with handler, or AsyncTask for this kind of long time taking tasks.

这篇关于IOException异常e是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆