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;
}

}
}

posted @ 2017-06-16 14:18  洞玄巅峰  阅读(341)  评论(2编辑  收藏  举报