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

您需要外部类实例。

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

或者干脆使内部类静态。

于 2013-02-22T18:32:25.393 回答
3

该类Tst应该是static,因为它没有附加到 的特定实例bwCalc

于 2013-02-22T18:32:14.377 回答