No enclosing instance of type XXX is accessible
标签:innert class
小编还为您整理了以下内容,可能对您也有帮助:
No enclosing instance of type Server is accessible
把 NetSocket c = new NetSocket(s1);按下面改
Server server = new Server();
NetSocket c = server.new NetSocket(s1);
No enclosing instance of type Server is accessible
把 NetSocket c = new NetSocket(s1);按下面改
Server server = new Server();
NetSocket c = server.new NetSocket(s1);
【android】No enclosing instance of the type MainActivity is accessible in scope
可以把类A定义为MainAcitivity的内部类,一个普通内部类(非static的)拥有它的外围类的所有成员的访问权限,也可以引用外围类的对象:外围类的名称.this
传对象
public class MainActivity extends Activity
{
……
public void anotherClass()
{
ClassA activity = new ClassA(this);
}
}
public class ClassA extends GridLayout
{
private MainActivity activity;
public ClassA(MainActivity activity)
{
this.activity = activity;
}
}
3. 传接口
public interface IActivity
{
// 与Activity里同名同参数的方法声明
}
public class MainActivity extends Activity implements IActivity
{
……
public void anotherClass()
{
AnotherClass activity = new AnotherClass(this);
}
}
public class AnotherClass
{
private IActivity iActivity;
public AnotherClass(IActivity iActivity)
{
this.iActivity = iActivity;
}
}
Java报错Multiple markers at this line - No enclosing instance of type Setapple is accessible.
把你的apple 类 改为静态的 即 public static class apple
你的主程序是public static main ,在java中,静态方法是不能调用动态方法的,只能是静态调用静态。
或者也可以按照提示所说 写成这样: apple a =new SetApple().new apple();