有时候,我在该行获得NullPointerException异常。请让我知道如何纠正这一点。在错误的时间,我已经检查了变量backgoundImage空值的可能性。变量backgoundImage不为null。
canvas.drawBitmap(backgoundImage,0,0,NULL);code:
@覆盖 公共无效的run(){ // TODO自动生成方法存根 ourHolder = getHolder(); 而(isRunning){ 如果(!ourHolder.getSurface()。的isValid()){ 继续; } 画布= ourHolder.lockCanvas(); screenCenterX = DWIDTH / 2; screenCenterY =做切片/ 2; // ------------------------------------------------ ----------------------------------- 如果(backgoundImage == NULL){ 尝试{ Log.i(DragDropCheck,---------------- backgoundImage为空--------); backgoundImage = getAssetImage(的getContext(),backgroundhomepage); canvas.drawBitmap(backgoundImage,0,0,NULL); }赶上(IOException异常五){ // TODO自动生成catch块 e.printStackTrace(); } }其他{ canvas.drawBitmap(backgoundImage,0,0,NULL); } // ------------------------------------------------ ----------------------------------- 如果(imagePublishDone){ 如果(!welcomeDone){ welcomeDone = TRUE; } moveImageInEllipticalPath(); }其他{ initialImagePublish(); } centreReached = FALSE; ourHolder.unlockCanvasAndPost(画布); } }的logcat
07-09 22:40:18.689:E / AndroidRuntime(8794):致命异常:螺纹62107-09 22:40:18.689:E / AndroidRuntime(8794):java.lang.NullPointerEception07-09 22:40:18.689:E / AndroidRuntime(8794):在com.eample.funandlearn.DragDrop $ MyBringBackSurface.run(DragDrop.java:645)07-09 22:40:18.689:E / AndroidRuntime(8794):在java.lang.Thread.run(Thread.java:856)解决方案
也许,问题是,画布变量空。你应该管理那些具体的案例来避免执行code当 ourHolder.lockCanvas()调用返回空(此外,你应该检查你的 ourHolder 变量不是执行,而循环)之前空。
Sometimes, I am getting NullPointerException in the line. Please let me know how to correct this. At the time of error, I have checked the possibility for the null value in variable backgoundImage. The variable backgoundImage is not null.
canvas.drawBitmap(backgoundImage, 0, 0 , null);Code:
@Override public void run() { // TODO Auto-generated method stub ourHolder = getHolder(); while (isRunning) { if (!ourHolder.getSurface().isValid()){ continue; } canvas = ourHolder.lockCanvas(); screenCenterX = dWidth / 2; screenCenterY = dHeight / 2; //----------------------------------------------------------------------------------- if(backgoundImage == null){ try { Log.i("DragDropCheck", "----------------backgoundImage is null--------"); backgoundImage = getAssetImage(getContext(),"backgroundhomepage"); canvas.drawBitmap(backgoundImage, 0, 0 , null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ canvas.drawBitmap(backgoundImage, 0, 0 , null); } //----------------------------------------------------------------------------------- if (imagePublishDone) { if(!welcomeDone){ welcomeDone=true; } moveImageInEllipticalPath(); } else { initialImagePublish(); } centreReached = false; ourHolder.unlockCanvasAndPost(canvas); } }logcat:
07-09 22:40:18.689: E/AndroidRuntime(8794): FATAL EXCEPTION: Thread-621 07-09 22:40:18.689: E/AndroidRuntime(8794): java.lang.NullPointerEception 07-09 22:40:18.689: E/AndroidRuntime(8794): at com.eample.funandlearn.DragDrop$MyBringBackSurface.run(DragDrop.java:645) 07-09 22:40:18.689: E/AndroidRuntime(8794): at java.lang.Thread.run(Thread.java:856)解决方案
Probably, the problem is that the canvas variable is null. You should manage that specific case to avoid executing code when the ourHolder.lockCanvas() call returns null (also, you should check that your ourHolder variable isn't null before executing the while loop).
更多推荐
帆布
发布评论