Java的一个错误提示

最近在写代码时,遇到一个错误提示,老是不知道为什么,于是google了一下,将结果写下来,供大家学习和交流。

 

错误提示:

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

 

原因是:

if you try to instantiate an inner class without an instance of the outer class.

在没有外部类对象时试图初始化一个内部类。

所以你应该先new一个外部类,然后通过它来new内部类

 

参见:

http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html

http://java.syntaxerrors.info/index.php?title=No_enclosing_instance_of_type_Foo_is_accessible._Must_qualify_the_allocation_with_an_enclosing_instance_of_type_Foo_(e.g._x.new_A()_where_x_is_an_instance_of_Foo).

 

 

 

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值