该文件包含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 – 终结者抛出的未捕获异常所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)