2016-05-31 10 views
-1

私のプログラムは完全にコンパイルされますが、実行しようとする度にNullPointerExceptionがスローされます。私はこれを検索しようとしましたが、プログラムがそれを使用しようとしている間にエラーがヌルであることに関連していますが、すべてを再チェックして空白になりました。私のNullPointerExceptionの原因

import hsa.Console; 
    import java.awt.*; 
    import java.util.* ; 
    public class PlatformAndBall2 
    { 
     static Console g ; 
     public static void BallLoop() throws InterruptedException 
    { 
    do { 

     int height = g.getHeight(); 
     int width = g.getWidth(); 
     int xpos,ypos ; xpos= 0; ypos =0 ; 
     int radius ; radius = 20 ; 
     int addx, addy ; addx = 3; addy = 3; 

     xpos += addx ; 
     ypos += addy ; 
     g.setColor(Color.red) ; 
     g.clear(); 
     g.fillOval(xpos,ypos,radius,radius) ; 

     Thread.sleep(15); // sets frames 

     if (xpos < 0) 
     addx += 3 ; 

     if (xpos > width - radius) 
     addx += -3 ;  

     if (ypos < 0) 
     addy += 3 ;  

     if (ypos > height -radius) 
     addy += -3 ; 
    }while (true); 
     } 
     public static void main(String[] args)throws InterruptedException { 

     Console g = new Console() ; 
     BallLoop(); 
     }} 
+0

これは、Javaの問題ではなく、JavaScriptの質問ですが、初期化しています。 – Pointy

+0

コード、期待/期待結果、実際の結果やエラーを常に含めてください。 – nateyolles

+0

あなたのデバッガはあなたに明快さを表示します。 – nicomp

答えて

0

静的フィールドstatic Console gは決して初期化されません。メインでは、ローカルConsole g = new Console();.初期g = new Console();

public static void main(String[] args)throws InterruptedException { 
    g = new Console(); 
    BallLoop(); 
} 
関連する問題