No enclosing instance of type Demo5 is accessible. Must qualify the allocation ......

于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以在不做其他变动的情况下,最简单的解决办法是将public class改为public static class.

时间: 2024-07-28 23:06:01

No enclosing instance of type Demo5 is accessible. Must qualify the allocation ......的相关文章

android No enclosing instance of type BasicActivity is accessible. Must qualify the allocation with

No enclosing instance of type BasicActivity is accessible. Must qualify the allocation with an enclosing instance of type BasicActivity (e.g. x.new A() where x is an instance of BasicActivity). 描述: 在BasicActivity.java中写了一个public class 的内部类,在另一个java文件

No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

package com.thread; public class Thread01 { public class Thread1 extends Thread{ private String name; public Thread1(String name){ this.name = name; } public void run() { for (int i = 0; i < 5; i++) { System.out.println(name+"运行:"+i); try { s

Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing 最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing ins

Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing[转]

最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E(e.g.  x.new A() where x is an instance of E). E指代我写的那个内部类. 根据提示,没有可访问的内部类E的实例,必须分配一

Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an enclosing instance of type caiquan (e.g. x.new A() where x is an instance of caiquan).

package test;import java.util.Scanner;import java.util.Random;public class caiquan { public static void main(String[] args){ Game g=new Game(); g.begin(); } //将这个类定义为静态就好了,也就说改成 static class Game class Game{ public void begin(){ System.out.println("*

java出现No enclosing instance of type main is accessible. Must qualify the allocation with an enclosing instance of type main (e.g. x.new A() where x is an instance of main).

根据提示,没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例.)看着这句提示,我就纳闷了,我已经用new实例化了这个类,为什么还不行呢.原来我写的内部类是动态的,也就是开头以public class开头.而主程序是public static class main.在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将publ

Java 出现 No enclosing instance of type Test1 is accessible.(转,自己也遇到了!)

最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E(e.g.  x.new A() where x is an instance of E). E指代我写的那个内部类. 根据提示,没有可访问的内部类E的实例,必须分配一

Java中出现No enclosing instance of type XXX is accessible问题

Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: Multiple markers at this line - The value of the local variable test is not used - No enclosing instance of type StaticCallDynamic is accessible. Must qualify the allocation with an enclosing insta

java解决 No enclosing instance of type XXX is accessible的问题

有些时候我们要把Activity的一些实现类移到java类里来实现,比如把写以下两个类: 在LifeCircle这个类中: public class LifeCircle { public class Mybroadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { } } } 如果在Activity这样去new: public class Setti