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

简介: p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px '.SF NS Text'}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).今天在写一个短信发送的工具类时使用到了内部类,在实例化内部类时遇到此错误。

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了。


目录
相关文章
|
6月前
|
小程序 JavaScript
Avoid mutating a prop directly since the value will be overwritten whenever the parent comp
Avoid mutating a prop directly since the value will be overwritten whenever the parent comp
|
Java Maven
An attempt was made to call a method that does not exist. The attempt was made from the following
An attempt was made to call a method that does not exist. The attempt was made from the following
462 0
|
JavaScript 算法 前端开发
Property xxx was accessed during render but is not defined on instance
目前el-form的model主要用表单验证的,也就是配合el-form的rules和el-form-item的prop来使用的。不信的话,你可以增加一个rules和prop(为了调用验证方法,也el-form也加一个ref属性,相当于id或者class选择器的意思),但是不写model,然后验证的话,会提示缺少model,导致无法验证成功。
Property xxx was accessed during render but is not defined on instance
can not be used when making a shared object; recompile with -fPIC
can not be used when making a shared object; recompile with -fPIC
314 0
|
JavaScript
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
The href attribute requires a valid value to be accessible
The href attribute requires a valid value to be accessible
226 0
|
fastjson
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
main方法中实例化内部类报错: public class TestGson { public static void main(String[] args) { Gson gson=new Gson();TestGson testgson=new TestGson(); Student student = testgson.
1354 0
is present but cannot be translated into a null value due to being declared as a primitive type
解决办法:把基本类型改为对象,譬如此处将pageId的类型由int 改为Integer 2016-10-19 19:36:11.275 DEBUG [http-nio-9999-exec-2][org.
2698 0