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).的更多相关文章

  1. 【转】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 ...

  2. 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   ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 【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. ...

  8. 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 ...

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

    在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将public clas ...

随机推荐

  1. OC + RAC (三) 信号中的信号

    -(void)_test3{ RACSubject *signalofsignal = [RACSubject subject]; //信号中的信号(也就是发送的数据是信号) RACSubject * ...

  2. python设置文字输出颜色

    #!/usr/bin/env python # -*- coding:utf-8 -*- """ @Time: 2018/5/5 20:43 @Author: Jun H ...

  3. [UOJ211][UER #6]逃跑

    题意:从原点出发,走\(n\)次,每次往四个方向中随机一个走,走每个方向有个概率,求所有方案走到过的点数的方差. 题解:orz kczno1 \(E*all=\sum (a_i-avg)^2*all= ...

  4. 【HDOJ6627】equation(模拟)

    题意:给定n,整数序列a和b,整数C,求所有成立的x n<=1e5,1<=a[i]<=1e3,-1e3<=b[i]<=1e3,1<=C<=1e9 思路: 大概 ...

  5. 【转】Django 模板语法

    转自:https://www.cnblogs.com/love9527/p/9077863.html Django 模板语法 一.模板 只要是在html里面有模板语法就不是html文件了,这样的文件就 ...

  6. git commit --amend用法(摘抄)

    适用场景: 比方说,你的代码已经提交到git库,leader审核的时候发现有个Java文件代码有点问题,于是让你修改,通常有2种方法: 方法1:leader 将你提交的所有代码 abandon掉,然后 ...

  7. T2691 桶哥的问题——送桶

    这个题其实不难,就是按照结束时候的顺序从大到小走一遍,能送的就送,如果区间不重合就更新一下 代码: #include<iostream> #include<cstdio> #i ...

  8. php-mbstring php7.0-zip

    sudo apt install php-mbstring sudo apt install zip unzip php7.0-zip

  9. SVN 忽略添加文件和文件夹

    你添加的文件和文件夹是没有加入版本控制的,是你新添加的,接下来的设置才有用 忽略这个文件的方式有两种 第一种方式 添加svn:ignore    右键文件-->TortoiseSvn--> ...

  10. 夜雨惊风 Linux下卸载openjdk,安装jdk

    1.查看java版本 1 2 3 4 [root@CFDB2 ~]# java -version openjdk version "1.8.0_171" OpenJDK Runti ...