异常: No enclosing instance of type xx is accessible. Must qualify (Java 内部类)
异常
前言. 开发时候遇到内部类的问题.
- 异常
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 内部类)相关推荐
- 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 ...
- Java出现No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosin
最近研究LDA源代码时,里面涉及到Comparable方法的使用.以前用过这个排序方法,现在想回顾一下.以下是程序,感觉没问题啊,结果报错了: Exception in thread "ma ...
- No enclosing instance of type FormDetailBean is accessible. Must qualify the allocation with an encl
最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...
- 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 ...
- 语法错误: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 没 ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
最新文章
- 蓝桥杯 扑克序列(全排列)
- Drupal8 社区文档之在Drupal中,查看网页的编辑一个页面的几乎是相同的
- 漫画:程序员一时单身一时爽,一直单身...有点惨
- js使用工具将表单封装成json字符串传到后台,js截取字符串(学生笔记)
- 微信公众号开发 重要 access_token {errcode:40164,errmsg:invalid ip 114.221.159.11, not in whitelist hint:
- char(128) mysql_char能表示(-128~127)
- 目标检测——感受野的学习笔记
- 我的世界java版怎么打开聊天栏_我的世界JAVA版才有的隐藏模式只有开发者才知道怎么进入...
- 深度学习进阶,Keras视频分类
- 两计算机网线连接打印机共享打印机共享打印机,打印机、资源共享、协同工作、一根网线连接两电脑的方...
- 预装windows 8 系统GPT模式的ThinkPad T440改装64位 windows 7旗舰版
- 杂项工具WinHex
- 第一周项目0-宣告主权
- List.stream()常用的操作
- Semantic Proximity Search on Heterogeneous Graph by Proximity Embedding
- 使用 Transformer 序列到序列的钢琴转录
- 怎么清晰地理解、表达 IaaS 、 PaaS 、 SaaS ?
- 服务器无限矿物指令,迷你世界刷矿物指令 | 手游网游页游攻略大全
- 鼠标移动事件(鼠标移动到主菜单上显示子菜单)
- 大话设计模式——UML图
热门文章
- STC8F2K08S2
- windows服务器安全事件日志事件编号与描述
- 微信小程序登陆凭证校验出现{errcode:40029,errmsg:invalid code, hints: [ req_id: weh8ka0297hc58 ]}
- 77. Combinations(组合)
- word文档中动态生成excel表格(基金公告系列讲解)
- java 卷轴式_天堂1 java 编写活动卷轴方法
- vue 路由重复跳转报错问题
- 笔记本电脑移动办公平台网络解决方案
- 定语从句和同位语重句的区别
- 数字图像处理与应用——图像和视频压缩技术