No enclosing instance of type ThreadTest is accessible.错误解决

来源:互联网 发布:淘宝买二手吉他靠谱吗 编辑:程序博客网 时间:2024/06/05 11:20
闲着学习了一下线程的知识,于是创建了一个类,跟着教材上敲了一下代码,结果在MyEclipse中出现了

No enclosing instance of type TestThread is accessible. Must qualify the allocation with an enclosing instance of type TestThread (e.g. x.new A() where x is an instance of TestThread).这样的错误提示,看看语义,翻译过来以后大概意思是:没有可访问的内部类TestThread的实例。百度了一下此项内容,大部分都是说类的动态和静态调用的问题,仔细看看原来是讲另一个类写在了main方法里面了,将其方法移出main方法之外出现以下情况
The public type Runner1 must be defined in its own file,至此问题很显然,原来需要另外new一个Runner1,将TestThread里面的Runner1删除就可以了,内中原理也一应明了,轻松解决。
0 0