java.lang.Throwable: Explicit termination method ‘close’ not called错误



java.lang.Throwable: Explicit termination method ‘close’ not called错误。

调试Android项目,发布新商品,读取图片File时报了Exception,但程序却没有影响,继续运行:

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
  • 1
  • 2
  • 1
  • 2

我查了一下这个错误,结合自己的项目分析:
1. IO文件流没有关闭,造成内存泄露
2. 开启StrictMode模式
3. 数据库查询的Customer没有关闭

我在项目中慢慢查询了 1和3 问题,并做了一些优化后发现还是报这个错误,最后把 StrictMode模式关闭了,就没有在报这个错误了,所以确定是因为开始了 StrictMode模式导致APP的检查比较严苛,报了这个错误。目前的处理的方法是暂时不理,继续开始StrictMode模式,以便开发调试中尽可能的优化APP。