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


目录
相关文章
|
3月前
|
小程序 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
|
9月前
|
数据库 OceanBase
RuntimeError: 'PluginContext' object has no attribute 'set_variable'
RuntimeError: 'PluginContext' object has no attribute 'set_variable'
84 2
|
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
232 0
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
49 0
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
|
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-
how to know which settype an assignment block is built based on
how to know which settype an assignment block is built based on
101 0
how to know which settype an assignment block is built based on
The href attribute requires a valid value to be accessible
The href attribute requires a valid value to be accessible
179 0