绘图画布FC
我有一个绘图画布,没有错误,但一直强制关闭。我不确定为什么强制关闭。我对画布一无所知,如果有人能帮助我那就太好了。
记录猫错误
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 Canvas.java
抛出 NPE 的唯一方法是位图为空。
你能检查一下以确保 kango 不为空吗?
Looking at Canvas.java
The only way this would throw a NPE is if bitmap was null.
Can you check to make sure kangoo is not null?
查看更多代码会有所帮助,但根据您链接到的教程,您的图像资源似乎不可用。您使用了 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?我发现问题出在我的
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 theSetContentView
tosetContentView(new Panel(this,null));
it worked fine.