绘图画布FC

发布于 2024-11-04 16:39:31 字数 1065 浏览 1 评论 0原文

我有一个绘图画布,没有错误,但一直强制关闭。我不确定为什么强制关闭。我对画布一无所知,如果有人能帮助我那就太好了。

记录猫错误

05-03 10:07:12.803: ERROR/AndroidRuntime(14042): FATAL EXCEPTION: Thread-9

05-03 10:07:12.803: ERROR/AndroidRuntime(14042): java.lang.NullPointerException

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at android.graphics.Canvas.throwIfRecycled(Canvas.java:954)

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at android.graphics.Canvas.drawBitmap(Canvas.java:980)

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at com.the.line.Panel.onDraw(Panel.java:59)

这是来自我的 Panel 类的第 59 行

canvas.drawBitmap(kangoo, 10, 10, null);

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at com.the.line.CanvasThread.run(CanvasThread.java:28)

这是来自我的 CanvasThread 类的第 28 行

_panel.onDraw(c);

我从教程中找到了这段代码 < a href="http://www.helloandroid.com/tutorials/how-use-canvas-your-android-apps-part-1" rel="nofollow">此处 如果有帮助的话。

I have a drawing canvas with no errors but keeps force closing. I am not sure why it is force closing. I know nothing about canvases if some one could hep me that would be great.

Log cat errors

05-03 10:07:12.803: ERROR/AndroidRuntime(14042): FATAL EXCEPTION: Thread-9

05-03 10:07:12.803: ERROR/AndroidRuntime(14042): java.lang.NullPointerException

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at android.graphics.Canvas.throwIfRecycled(Canvas.java:954)

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at android.graphics.Canvas.drawBitmap(Canvas.java:980)

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at com.the.line.Panel.onDraw(Panel.java:59)

This is from line 59 of my Panel class

canvas.drawBitmap(kangoo, 10, 10, null);

05-03 10:07:12.803: ERROR/AndroidRuntime(14042):     at com.the.line.CanvasThread.run(CanvasThread.java:28)

This is from line 28 of my CanvasThread class

_panel.onDraw(c);

I found this code from a tutorial here if that helps.

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

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

发布评论

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

评论(3

一刻暧昧 2024-11-11 16:39:32

查看 Canvas.java

private static void throwIfRecycled(Bitmap bitmap) {
    if (bitmap.isRecycled()) {
        throw new RuntimeException(
                    "Canvas: trying to use a recycled bitmap " + bitmap);
    }
}

抛出 NPE 的唯一方法是位图为空。

你能检查一下以确保 kango 不为空吗?

Looking at Canvas.java

private static void throwIfRecycled(Bitmap bitmap) {
    if (bitmap.isRecycled()) {
        throw new RuntimeException(
                    "Canvas: trying to use a recycled bitmap " + bitmap);
    }
}

The only way this would throw a NPE is if bitmap was null.

Can you check to make sure kangoo is not null?

暖风昔人 2024-11-11 16:39:32

查看更多代码会有所帮助,但根据您链接到的教程,您的图像资源似乎不可用。您使用了 R.drawable.kangoo 代码还是做了其他事情?

Bitmap kangoo = BitmapFactory.decodeResource(getResources(),
                            R.drawable.kangoo);

Seeing more of the code would help, but based off of the tutorial you linked to, it looks like your image resource is not available. Did you use the R.drawable.kangoo code or did you do something else?

Bitmap kangoo = BitmapFactory.decodeResource(getResources(),
                            R.drawable.kangoo);
你不是我要的菜∠ 2024-11-11 16:39:32

我发现问题出在我的 setContentView 中,它被设置为“setContentView(R.layout.main)”,但我没有在其中使用任何 xml 文件,所以当我更改 SetContentView 时setContentView(new Panel(this,null)); 它工作得很好。

I figured it out the problem was in my setContentView it was set to 'setContentView(R.layout.main)' witch I am not using any xml file in this so when I changed the SetContentView to setContentView(new Panel(this,null)); it worked fine.

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