[在尝试使用静态对象后出现很多异常

问题描述 投票:-1回答:1

所以我创建了我的Platform类的实例:

   //platform initialization 
   static Platform p;

   //method to fill in the platform   
   public void makePlatform() {  
      double x = 100; 
      double y = 800;
      Color c; 
      //platform is black
      c = new Color(1,1,1); 
      p = new Platform(x,y, c);
   }

而且我正在其他方法中使用这些变量:

public void run() {

    while(true) {
//the control array is boolean for controls
         if(controls[1])
            p.x++;

         if(controls[0])
            p.x--;

         if (p.x > 335 || p.x < 0) {
            p.x = -p.x;
         }
  }
}

我在指向p.x的行时遇到了很多异常。实例化有什么问题?

java oop exception nullpointerexception
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.