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

No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing相关推荐

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

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

  2. 语法错误:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    错误 问题 No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing 没 ...

  3. No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instanc

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

  4. No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing i...

    最近在刷AC,在编译时出现: No enclosing instance of type Main is accessible. Must qualify the allocation with an ...

  5. Java出现No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosin

    最近研究LDA源代码时,里面涉及到Comparable方法的使用.以前用过这个排序方法,现在想回顾一下.以下是程序,感觉没问题啊,结果报错了: Exception in thread "ma ...

  6. No enclosing instance of type FormDetailBean is accessible. Must qualify the allocation with an encl

    最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...

  7. No enclosing instance of type TextRunnable is accessible. Must qualify the allocation with an enclo

    今天写demo的时候,遇到一个问题,关于内部类的,这里写一下 错误信息:No enclosing instance of type TextRunnable is accessible. Must q ...

  8. [Java]Error:No enclosing instance of type E is accessible. Must qualify the allocation with an enclo

    在自己试着写一个链表的例子时,由于参考的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible. Must ...

  9. No enclosing instance of type testTry is accessible. Must qualify the allocation...之解决方法

    报错原因: 因为在做异常处理测试时,我写的内部类是动态的,即public class开头无static关键字修饰,而测试主程序是静态的main方法:在Java中,类中的静态方法不能直接调用动态方法.只 ...

最新文章

  1. CV00-01-开篇与环境搭建
  2. java超线程_超线程多核心下Java多线程编程技术分析
  3. 牛人的博客(机器学习,图像处理,计算机视觉)
  4. java_二进制的前导的零
  5. systemverilog硬件设计及建模_UVM方法学与设计模式(一):从OOP的本质,设计模式到设计原则...
  6. cydia源_Cydia常见错误提示(红字/黄字)
  7. error_reporting()函数
  8. VS2010创建OCX控件
  9. Algorithm Analysis: common functions, asymptotic notation
  10. [转]技术以外的功夫
  11. 函的红头文件格式制作_如何利用Word“智能函头”简单制作“红头文件”公文模板...
  12. Adobe Camera Raw v15.0.0.1264 增效工具
  13. 福禄克光纤测试:多模光纤 VS 单模光纤
  14. 电脑启动快捷键一览表
  15. 2021-10-21 centos7+ nginx + uwsgi(包含一个配置上的天坑)
  16. 正则表达式(Regular Expression)——入门笔记(常用正则表达式符号、正则表达式在线调试工具)
  17. 计算机任务计划程序已损坏,Win7-该任务映像已损坏或已篡改。(异常来自HRESULT:0x80041321)解决办法...
  18. ESP8266 MP3制作——关于SelectionList从源码中改代码的一次经历
  19. 区块链详细应用举例(一)
  20. extjs 4.1 用户管理界面设计

热门文章

  1. Tomcat中web.xml文件的详细说明
  2. WebKit中的Chrome和ChromeClient
  3. Python架构(一)
  4. java常用代码总结
  5. Flutter入门:Hero共享元素
  6. SDNU 1178.能量项链(区间dp)
  7. java:提示Could not initialize class sun.awt.X11GraphicsEnvironment
  8. php设计模式 -- 工厂模式
  9. Java面试题集(二)list与Map相关知识(1.2)
  10. Java IO流及应用(一)