问题描述
我是从我的一个简单的按钮,点击应用程序的一些错误消息。之后,点击动画应该开始,但按钮变得更大。它完美地运行在大多数的设备,但在一些(我认为主要是4.X以上)崩溃。
I got some error messages from my application on a simple button click. After the click an animation should start, but the button becomes bigger. It runs perfectly on most devices, but on some (i think mostly 4.X and above) it crashes.
异常消息(堆栈跟踪):
Exception message (Stack Trace):
java.lang.NullPointerException
at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:118)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:400)
at android.view.View.draw(View.java:10999)
at android.view.ViewGroup.drawChild(ViewGroup.java:3186)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788)
at android.view.ViewGroup.drawChild(ViewGroup.java:3184)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788)
at android.view.ViewGroup.drawChild(ViewGroup.java:3184)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788)
at android.view.ViewGroup.drawChild(ViewGroup.java:3184)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2788)
at android.view.View.draw(View.java:11017)
at android.view.View.getDisplayList(View.java:10444)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2896)
at android.view.View.getDisplayList(View.java:10407)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2896)
at android.view.View.getDisplayList(View.java:10407)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2896)
at android.view.View.getDisplayList(View.java:10407)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:883)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2089)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1781)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2666)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4977)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
在此先感谢!
Thanks in advance!
推荐答案
我一直在寻找这个问题的答案在过去的几天。它记录在ICS,但我已经在我的测试电话的三星Galaxy S3运行4.1.2人注意到它。大多数人建议关闭硬件加速;我并不想这样做的原因硬件加速使我的动画,所以如丝般柔滑。因此,我发现是,如果我重写平局()尝试捕捉空指针异常的硬件加速功能的工作(大部分时间),并足以让你永远也不会注意到他们没有工作或抛出异常。
I've been searching for the answer to this for the last couple days. It’s documented in ICS but I have noticed it in one of my test phones a Samsung Galaxy S3 running 4.1.2. Most people suggest turning off hardware acceleration; I didn't want to do that cause hardware acceleration makes my animations so silky smooth. So what I found was if I override draw() try and catch the null pointer exception the hardware accelerated features work (most of the time) and enough for you to never notice they aren't working or throwing the exception.
@Override
public void draw(Canvas canvas) {
try{
super.draw(canvas);
}catch(java.lang.NullPointerException e){
//you can log if you want to you can leave your friends behind
//Log.e("mytag","MyCustomView::draw():"+e);
}
}
这篇关于NullPointerException异常与Hardwareacceleration打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!