异常

前言. 开发时候遇到内部类的问题.

  • 异常
No enclosing instance of type SparkProgrammingGuide is accessible. Must qualify the allocation with an enclosing instance of type SparkProgrammingGuide (e.g. x.new A() where x is an instance of SparkProgrammingGuide).
  • 代码如下
 // 注意 static class GetLength implements Function<String, Integer> {public Integer call(String s) {return s.length();}}class Sum implements Function2<Integer, Integer, Integer> {public Integer call(Integer a, Integer b) {return a + b;}}// 继承方法的形式进行运行.// 特别注意 局部类 No enclosing instance of type XXX is accessible. Must qualify 异常.static int getTotalLengthByExtendsFunction(JavaSparkContext context) {int totalLength = 0;if (null != context) {JavaRDD<String> distFile = context.textFile("data/wordcount/spark-overview.txt");JavaRDD<Integer> linesRDD = distFile.map(new GetLength());totalLength = linesRDD.reduce(new Sum());}return totalLength;}

解决措施

  • 方法1
    将局部类设置为静态的. 类名前添加<static>关键字即可.
static class Sum implements Function2<Integer, Integer, Integer> {public Integer call(Integer a, Integer b) {return a + b;}}
  • 方法2
    通过类名.局部类名访问即可. 即如下的new ParentClassName().new GetLength().
JavaRDD<Integer> linesRDD = distFile.map(new ParentClassName().new GetLength());
  • 方法3
    不使用局部类即可. 作为非public类型类写在一个文件即可.

Reference

[1] JAVA在编写内部类时No enclosing instance of type XXX is accessible. Must qualify原因及解决.
[2] No enclosing instance of type 类名 is accessible. Must qualify the allocation with.

异常: No enclosing instance of type xx is accessible. Must qualify (Java 内部类)相关推荐

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

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

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

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

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

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

  4. 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 ...

  5. 语法错误: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 没 ...

  6. 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 ...

  7. [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 ...

  8. 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 ...

  9. 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 ...

最新文章

  1. 蓝桥杯 扑克序列(全排列)
  2. Drupal8 社区文档之在Drupal中,查看网页的编辑一个页面的几乎是相同的
  3. 漫画:程序员一时单身一时爽,一直单身...有点惨
  4. js使用工具将表单封装成json字符串传到后台,js截取字符串(学生笔记)
  5. 微信公众号开发 重要 access_token {errcode:40164,errmsg:invalid ip 114.221.159.11, not in whitelist hint:
  6. char(128) mysql_char能表示(-128~127)
  7. 目标检测——感受野的学习笔记
  8. 我的世界java版怎么打开聊天栏_我的世界JAVA版才有的隐藏模式只有开发者才知道怎么进入...
  9. 深度学习进阶,Keras视频分类
  10. 两计算机网线连接打印机共享打印机共享打印机,打印机、资源共享、协同工作、一根网线连接两电脑的方...
  11. 预装windows 8 系统GPT模式的ThinkPad T440改装64位 windows 7旗舰版
  12. 杂项工具WinHex
  13. 第一周项目0-宣告主权
  14. List.stream()常用的操作
  15. Semantic Proximity Search on Heterogeneous Graph by Proximity Embedding
  16. 使用 Transformer 序列到序列的钢琴转录
  17. 怎么清晰地理解、表达 IaaS 、 PaaS 、 SaaS ?
  18. 服务器无限矿物指令,迷你世界刷矿物指令 | 手游网游页游攻略大全
  19. 鼠标移动事件(鼠标移动到主菜单上显示子菜单)
  20. 大话设计模式——UML图

热门文章

  1. STC8F2K08S2
  2. windows服务器安全事件日志事件编号与描述
  3. 微信小程序登陆凭证校验出现{errcode:40029,errmsg:invalid code, hints: [ req_id: weh8ka0297hc58 ]}
  4. 77. Combinations(组合)
  5. word文档中动态生成excel表格(基金公告系列讲解)
  6. java 卷轴式_天堂1 java 编写活动卷轴方法
  7. vue 路由重复跳转报错问题
  8. 笔记本电脑移动办公平台网络解决方案
  9. 定语从句和同位语重句的区别
  10. 数字图像处理与应用——图像和视频压缩技术