如何调查在 Android 中使用 BitmapFactory 加载位图的问题? “getEntry 失败,因为 EntryIndex...”

发布于 2024-12-14 06:17:50 字数 2124 浏览 2 评论 0原文

我正在尝试加载位图并将其显示在画布上。我之前用这个方法做过,效果很好。不幸的是,这次出了问题,我不知道如何找出问题所在。

我的代码到达这里:

Log.d(TAG, "Loading bitmaps");
this.stageL=BitmapFactory.decodeResource(getResources(), R.drawable.stagel);
Log.d(TAG,"Bitmap loaded");
int stageLHeight = stageL.getHeight();
Log.d(TAG,String.valueOf(stageLHeight));

但是随后我在 Loading bitmapsBitmap Loaded 之间的 logcat 中收到警告。之后应用程序强制关闭,我再也看不到 stageLHeight 的值。

这是 logcat:

11-07 15:22:50.182: DEBUG/LabSetup(613): Loading bitmaps
11-07 15:22:50.182: WARN/ResourceType(613): getEntry failing because entryIndex 3 is beyond type entryCount 1
11-07 15:22:50.182: WARN/ResourceType(613): Failure getting entry for 0x7f020003 (t=1 e=3) in package 0 (error -2147483647)
11-07 15:22:50.182: DEBUG/LabSetup(613): Bitmap loaded
11-07 15:22:50.222: WARN/dalvikvm(613): threadid=9: thread exiting with uncaught exception (group=0x40014760)
11-07 15:22:50.222: ERROR/AndroidRuntime(613): FATAL EXCEPTION: Thread-10
11-07 15:22:50.222: ERROR/AndroidRuntime(613): java.lang.NullPointerException
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.LabSetup.SetCanvasSize(LabSetup.java:53)
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.MainAppPanel.onDraw(MainAppPanel.java:136)
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.MainThread.run(MainThread.java:56)

如果它有用,请查看 R.java:

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
        public static final int mag=0x7f020001;
        public static final int magr=0x7f020002;
        public static final int stagel=0x7f020003;
        public static final int stager=0x7f020004;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

I'm trying to load a bitmap and display it on a canvas. I've done it previously using this method and it's worked fine. Unfortunately, something has gone wrong this time and I don't know how I can track down the problem.

My code gets to here:

Log.d(TAG, "Loading bitmaps");
this.stageL=BitmapFactory.decodeResource(getResources(), R.drawable.stagel);
Log.d(TAG,"Bitmap loaded");
int stageLHeight = stageL.getHeight();
Log.d(TAG,String.valueOf(stageLHeight));

But then I get a warning in the logcat in-between Loading bitmaps and Bitmap Loaded. After that the app force closes and I never see the value of stageLHeight.

Here's the logcat:

11-07 15:22:50.182: DEBUG/LabSetup(613): Loading bitmaps
11-07 15:22:50.182: WARN/ResourceType(613): getEntry failing because entryIndex 3 is beyond type entryCount 1
11-07 15:22:50.182: WARN/ResourceType(613): Failure getting entry for 0x7f020003 (t=1 e=3) in package 0 (error -2147483647)
11-07 15:22:50.182: DEBUG/LabSetup(613): Bitmap loaded
11-07 15:22:50.222: WARN/dalvikvm(613): threadid=9: thread exiting with uncaught exception (group=0x40014760)
11-07 15:22:50.222: ERROR/AndroidRuntime(613): FATAL EXCEPTION: Thread-10
11-07 15:22:50.222: ERROR/AndroidRuntime(613): java.lang.NullPointerException
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.LabSetup.SetCanvasSize(LabSetup.java:53)
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.MainAppPanel.onDraw(MainAppPanel.java:136)
11-07 15:22:50.222: ERROR/AndroidRuntime(613):     at com.cjs.duallaseralignment.MainThread.run(MainThread.java:56)

And in case it's useful, the R.java:

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
        public static final int mag=0x7f020001;
        public static final int magr=0x7f020002;
        public static final int stagel=0x7f020003;
        public static final int stager=0x7f020004;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜司空 2024-12-21 06:17:50

错误出现在您的 Logcat 中。

11-07 15:22:50.222: ERROR/AndroidRuntime(613): at com.cjs.duallaseralignment.LabSetup.SetCanvasSize(LabSetup.java:53)

如果您能指出第 53 行,将会有所帮助。

由于您没有得到告诉您图像大小的日志,我猜测那

int stageLHeight = stageL.getHeight();

是第 53 行。我的下一个猜测是加载的图像为空。
如果图像不存在,或者无法从资源文件中解码图像,则可能会发生这种情况。

The error is there in your Logcat.

11-07 15:22:50.222: ERROR/AndroidRuntime(613): at com.cjs.duallaseralignment.LabSetup.SetCanvasSize(LabSetup.java:53)

It would help if you could point out line 53.

Since you don't get the log telling you the size of the image I would guess that

int stageLHeight = stageL.getHeight();

is Line 53. And my next guess is that the loaded image is null.
This can happen if the images do not exist, or if the images can not be decoded from the ressource file.

微暖i 2024-12-21 06:17:50

天哪,该死!

作为最后的手段,我从项目中删除了图像并重新添加它们,嘿,急!诡异的...

Gosh darn it!

As a last resort I deleted the images from the project and re-added them, and hey-presto! Weird...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文