您的位置:首页 > 其它

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

2018-01-12 17:36 447 查看
No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing instance of type SmsUtils (e.g. x.new A() where x is an instance of SmsUtils).
今天在写一个短信发送的工具类时使用到了内部类,在实例化内部类时遇到此错误。SmsResult result = new SmsResult();没有可以访问SmsUtils类型的封闭实例。必须使用封闭的SmsUtils类型的实例来限定分配(例如,x.new A(),其中x是SmsUtils的一个实例)。
SmsResult 是一个(非静态的)内部类。 正在从静态上下文创建它。您需要提供一个Server实例作为外部实例。但是,几乎可以肯定我想让 SmsResult 成为一个静态的嵌套类,或者可能是一个外部类。
刚好今天看到一篇文章中提到: 今天面试我问你static关键字有哪些作用,如果你答出static修饰变量、修饰方法我会认为你合格,答出静态块,我会认为你不错,答出静态内部类我会认为你很好,答出静态导包我会对你很满意,因为能看出你非常热衷研究技术。

给 SmsResult 类的定义添加 static 关键字就ok了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐