How to avoid this NullPointerException

前端 未结 3 901
礼貌的吻别
礼貌的吻别 2021-01-23 02:30

I\'m working on a small arcade video game, and I am looking to double buffer to improve animation. I have one class that\'s supposed to draw the blank image, and another class t

3条回答
  •  孤街浪徒
    2021-01-23 03:09

    Since MC extends render, the dbg you are referring to belongs to the MC instance that called draw. You can fix it by calling

    render.dbg.drawLine( 100, 100, 200, 200 );
    

    or take advantage of the inheritance you implemented

    class MC extends Render {
        //MC is a render, so you don't need to create another one
        public void draw() {
            gameRender(); //Call the MC's own gameRender
            dbg.drawLine( 100, 100, 200, 200 );  //Calling gameRender initialized dbg so you won't get a NullPointerException
        }
    }
    

提交回复
热议问题