No enclosing instance of type TestGson is accessible. Must qualify the allocation with an enclosing instance of type TestGson (e.g. x.new A() where x is an instance of TestGson).
main方法中实例化内部类报错:
public class TestGson {
public static void main(String[] args) {
Gson gson=new Gson();
TestGson testgson=new TestGson();
Student student = testgson.new Student();
student.setId(2);
student.setName("金旭东");
String strstudent = gson.toJson(student);
Object students = JSONObject.toJSON(student);
System.out.println("gosn="+strstudent+"fastjson="+students.toString());
}
class Student{
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
No enclosing instance of type TestGson is accessible. Must qualify the allocation with an enclosing instance of type TestGson (e.g. x.new A() where x is an instance of TestGson).的更多相关文章
- 【转】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 ...
- 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 ...
- No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an
在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...
- No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
之前看内部类的时候没发现这个问题,今天写代码的时候遇到,写个最简单的例子: 下面这一段代码 红色的部分就是编译报错: No enclosing instance of type Outer is ac ...
- No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: No enclosing instance of type Test is accessibl ...
- No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo).
No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing inst ...
- 【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A
用 eclipse 写 Java 代码时出现了这个问题,详细如下: No enclosing instance of type TestParsingLinkedList is accessible. ...
- No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst
今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将public clas ...
随机推荐
- Dubbo学习-1-基础知识
分布式基础理论 1.什么是分布式系统: 分布式系统是若干独立计算机的集合,这些计算机对于用户来说就像是单个相关系统.分布式系统是建立在网络之上的软件系统 随着互联网发展,网站应用规模的不断扩大,常规的 ...
- 04 全局配置,java 编意默认版本,1.6.修改配置
https://www.cnblogs.com/liu-s/p/5371289.html <!-- 修改Intellij Idea 创建maven项目默认Java编译版本 --> < ...
- 使用 Visual Studio 调试器附加到运行的进程
为什么调试附加进程? Visual Studio 调试器可以附加到在 Visual Studio 外运行的进程. 可以使用此附加功能执行以下操作: 调试并非在 Visual Studio 中创建的应用 ...
- Python3解leetcode Reach a Number
问题描述: You are standing at position 0 on an infinite number line. There is a goal at position target. ...
- mysql in与or效率比较
转自[点击]
- 不同vlan之间相互通信
不同VLAN之间相互通信的两种方式 (单臂路由.三层交换) 试验目的: 1.通过单臂路由实现不同VLAN之间的通信 2.通过三层交换路由功能实现不同VLAN之间的通信 网络拓扑图: 1.单臂路由实 ...
- SVG绘制多个圆
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux:VIM简单入手
现在的Linux系统一般都会默认安装VIM编辑器,如果没有安装VIM编辑器,也默认一定会有VI编辑器,VI编辑器产生的时间比鼠标来的更早,虽然功能很强大,但我建议安装VIM工具,安装了VIM之后,VI ...
- PHPer面试指南-laravel 篇
简述 Laravel 的生命周期 Laravel 采用了单一入口模式,应用的所有请求入口都是 public/index.php 文件. 注册类文件自动加载器 : Laravel通过 composer ...
- JedisPool使用注意事项
转自:http://www.cnblogs.com/wangxin37/p/6397783.html JedisPool使用注意事项: 1.每次从pool获取资源后,一定要try-finally释放, ...