0

non static variable this cannot be referenced from a static context次のコードのコンパイル時にエラーが発生しました。何が問題ですか?

class bwCalc {
    class Tst{
     public void tst() {
         byte[] data = new byte[1024];//1 kb buffer
         int count;
         long startedAt = System.currentTimeMillis();
         while((System.currentTimeMillis()-startedAt)<1) {
             System.out.println("hello\n");
         }

     }
 }
 public static void main(String argc[]) {
     Tst c = new Tst();
     c.tst();  
 }
}
4

2 に答える 2

4

Outer クラスのインスタンスが必要です。

bwCalc  b = newbwCalc ();     
     Tst c = b.new Tst();
         c.tst();  

または、単純に内部クラスを静的にします。

于 2013-02-22T18:32:25.393 に答える
3

の特定のインスタンスにアタッチされていないため、Tstクラスは である必要があります。staticbwCalc

于 2013-02-22T18:32:14.377 に答える