gpt4 book ai didi

java - 在 android 中解决 java.lang.Throwable 异常

转载 作者:行者123 更新时间:2023-11-30 02:12:59 25 4
gpt4 key购买 nike

我正在开发一个具有 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 正在通过 Binder 接到电话)。

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

关于java - 在 android 中解决 java.lang.Throwable 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com