Android – 终结者抛出的未捕获异常

Android – 终结者抛出的未捕获异常,第1张

概述我有这段代码,它接受服务器响应并将其写入文件. 该文件包含json数据.我将响应写入文件以便按顺序扫描json并避免在List中加载大的json数据! 我认为这种方法会引发异常,但我不确定! public File getData(final String url) throws URISyntaxException, AuthenticationException, IOException, C 我有这段代码,它接受服务器响应并将其写入文件.

该文件包含Json数据.我将响应写入文件以便按顺序扫描Json并避免在List中加载大的Json数据!

我认为这种方法会引发异常,但我不确定!

public file getData(final String url) throws URISyntaxException,AuthenticationException,IOException,ClIEntProtocolException,httpResponseException {    final httpGet getRequest = new httpGet(new URI(url));    final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username,password);    getRequest.addheader(new BasicScheme().authenticate(creds,getRequest));    getRequest.setheader("Content-Type","application/Json");    final ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler();    final byte[] responseBody = mClIEnt.execute(getRequest,responseHandler);    final file output = new file(fileConfig.TEMP_PATH + System.currentTimeMillis()+".Json");    final fileOutputStream fos = new fileOutputStream(output.getPath());     fos.write(responseBody);    fos.close();    return output;}

但我最近注意到了(我不知道为什么)我得到这个例外:

01-22 07:45:51.809: E/System(9055): Uncaught exception thrown by finalizer01-22 07:45:51.833: E/System(9055): java.io.IOException: close Failed: EIO (I/O error)01-22 07:45:51.833: E/System(9055):     at libcore.io.IoUtils.close(IoUtils.java:41)01-22 07:45:51.833: E/System(9055):     at java.io.fileinputStream.close(fileinputStream.java:121)01-22 07:45:51.833: E/System(9055):     at java.io.fileinputStream.finalize(fileinputStream.java:142)01-22 07:45:51.833: E/System(9055):     at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:185)01-22 07:45:51.833: E/System(9055):     at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)01-22 07:45:51.833: E/System(9055):     at java.lang.Thread.run(Thread.java:856)01-22 07:45:51.833: E/System(9055): Caused by: libcore.io.ErrnoException: close Failed: EIO (I/O error)01-22 07:45:51.833: E/System(9055):     at libcore.io.Posix.close(Native Method)01-22 07:45:51.833: E/System(9055):     at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)01-22 07:45:51.833: E/System(9055):     at libcore.io.IoUtils.close(IoUtils.java:38)01-22 07:45:51.833: E/System(9055):     ... 5 more01-22 07:45:51.833: E/System(9055): Uncaught exception thrown by finalizer01-22 07:45:51.841: E/System(9055): java.io.IOException: close Failed: EIO (I/O error)01-22 07:45:51.841: E/System(9055):     at libcore.io.IoUtils.close(IoUtils.java:41)01-22 07:45:51.841: E/System(9055):     at java.io.fileinputStream.close(fileinputStream.java:121)01-22 07:45:51.841: E/System(9055):     at java.io.fileinputStream.finalize(fileinputStream.java:142)01-22 07:45:51.841: E/System(9055):     at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:185)01-22 07:45:51.841: E/System(9055):     at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)01-22 07:45:51.841: E/System(9055):     at java.lang.Thread.run(Thread.java:856)01-22 07:45:51.841: E/System(9055): Caused by: libcore.io.ErrnoException: close Failed: EIO (I/O error)01-22 07:45:51.841: E/System(9055):     at libcore.io.Posix.close(Native Method)01-22 07:45:51.841: E/System(9055):     at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)01-22 07:45:51.841: E/System(9055):     at libcore.io.IoUtils.close(IoUtils.java:38)01-22 07:45:51.841: E/System(9055):     ... 5 more

一切似乎都有效,但我对这个例外感到困惑.

targetSdk确定我的应用程序是13.

感谢您的任何评论/回复!

解决方法 更新你的代码这样的事情.

public file getData(final String url) throws URISyntaxException,httpResponseException {    fileOutputStream fos = null;    file output = null;    final httpGet getRequest = new httpGet(new URI(url));    final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(            username,"application/Json");    final ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler();    final byte[] responseBody = mClIEnt            .execute(getRequest,responseHandler);    try {        output = new file(fileConfig.TEMP_PATH + System.currentTimeMillis()                + ".Json");        fos = new fileOutputStream(output.getPath());        fos.write(responseBody);        fos.flush();        fos.close();    } catch (fileNotFoundException e) {    } catch (IOException e) {    } catch (Exception e) {    } finally {        if (fos != null) {            fos = null;        }    }    return output; }

因为当你尝试fos.wrire()或fos.close()时,它可能通过IOException和你调用新的fileOutputStream(output.getPath());它可能通过fileNotFoundException.

总结

以上是内存溢出为你收集整理的Android – 终结者抛出的未捕获异常全部内容,希望文章能够帮你解决Android – 终结者抛出的未捕获异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126841.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存