关于ZAKER 融媒体解决方案 合作 加入

解决 Android 中的 java.lang.Throwable 异常

CocoaChina 10-13

我正在使用具有 sqlite 数据库的android应用程序 . 在我的应用程序中编写了与数据库操作相关的代码后 , 我遇到了以下异常 . 虽然我的应用程序不会停止 / 崩溃 , 但是我想知道如何解决此异常 . 我不确定为什么会发生此异常 , 但是我想它与 sqlite 操作有关 . 我已按照建议关闭了所有流 , 连接和游标 . 下面是堆栈跟踪:

689-698/? E/StrictMode﹕ 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 at dalvik.system.CloseGuard.open ( CloseGuard.java:184 ) at android.os.ParcelFileDescriptor.<init> ( ParcelFileDescriptor.java:180 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:916 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:906 ) at android.app.IBackupAgent$Stub.onTransact ( IBackupAgent.java:57 ) at android.os.Binder.execTransact ( Binder.java:446 ) 04-24 08:49:21.127 689-698/? E/StrictMode﹕ 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 at dalvik.system.CloseGuard.open ( CloseGuard.java:184 ) at android.os.ParcelFileDescriptor.<init> ( ParcelFileDescriptor.java:180 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:916 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:906 ) at android.app.IBackupAgent$Stub.onTransact ( IBackupAgent.java:64 ) at android.os.Binder.execTransact ( Binder.java:446 ) 04-24 08:49:21.129 689-698/? E/StrictMode﹕ 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 at dalvik.system.CloseGuard.open ( CloseGuard.java:184 ) at android.os.ParcelFileDescriptor.<init> ( ParcelFileDescriptor.java:180 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:916 ) at android.os.ParcelFileDescriptor$1.createFromParcel ( ParcelFileDescriptor.java:906 ) at android.app.IBackupAgent$Stub.onTransact ( IBackupAgent.java:71 ) at android.os.Binder.execTransact ( Binder.java:446 )

谁能解释这个异常何时发生以及如何解决?

最佳答案

就像日志说:

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.

Explicit termination method ‘ close ’ not called

请注意 , 调用堆栈显示了创建资源的位置 . 当资源被垃圾回收并且它没有被关闭时 , 将显示该消息 .

在您的情况下 , 我们可以看到该资源是一个 ParcelFileDescriptor, 它是由 IBackupAgent $Stub.onTransact ( ) 方法自动创建的 ( 即 , 当您的 BackupAgent 通过活页夹获得调用时 ) .

如果您确保关闭传递给 BackupAgent 子类的 ParcelFileDescriptors, 则日志应消失 .

以上内容由"CocoaChina"上传发布 查看原文

觉得文章不错,微信扫描分享好友

扫码分享

热门推荐

查看更多内容