帆布

编程入门 行业动态 更新时间:2024-10-25 18:34:58
本文介绍了帆布 - 空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有时候,我在该行获得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).

更多推荐

帆布

本文发布于:2023-08-02 17:53:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279884.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帆布

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!