今天周六没事就写点java方面的基础知识,平时在Q上也会有网友问我关于内部类报错方面的问题,如报这样的错误:
【
No enclosing instance of type TestThread is accessible. Must qualify the allocation with an enclosing instance of type TestThread (e.g. x.new A() where x is an instance of
TestThread).
】
或是:
【
Multiple markers at this line
- No enclosing instance of type TestThread is accessible. Must qualify the allocation with an enclosing instance of type TestThread (e.g. x.new A() where x
is an instance of TestThread).
- The value of the local variable tt is not used
】
其实这样的错误提示不是很明了,不太清楚,但你只要把握几点就不能出错:
在公共类(public claass xx {})中创建并使用内部类时无非有这两种形式:
1.
public class Test{
public static void main(String args[]){
TicketThread ticket = new TicketThread ();
new Thread (ticket).start();
new Thread (ticket).start();
new Thread (ticket).start();
}
private static class TicketThread implements Runnable{ //这里必须加上static 因为在main方法中要用到,且
//main方法是static的。若不在main方法中用可去掉
public void run(){
.....................
}
}
}
2.也可以这样来写:
public class Test{
public static void main(String args[]){
TicketThread ticket = new TicketThread ();
new Thread (ticket).start();
new Thread (ticket).start();
new Thread (ticket).start();
}
}
class TicketThread implements Runnabl{
public void run(){
.....................
}
}
总结:通常报以上两种错误提示的问题主要是因为没有处理好static 。
先写到这里,
更多交流、更多了解:
QQ:444084929 个人主页:http://www.huiqinbo.com
分享到:
相关推荐
用于初学着 对错误提示的解释理解 提高学习速度 还还学习吧 希望对你有帮助
使用Eclipse 进行项目开发,在实现类中的方法前面如果添加@Override就提示“Multiple markers at this line”的错误,问题
用QML编写的一个学习实例,可以打开文本文件或图片等格式的文件。hello world
配置dubbo协议时,报错。缺少dubbo.xsd文件。别人要5积分,我这给你们更低的,只为支持开发工作者。
Leaflet.Canvas-Markers-0.2.0 https://github.com/corg/Leaflet.Canvas-Markers
Multiple-markers-on-google-maps
This is the command line mp4 multiplexer tool from the mpeg4ip project. It is used to multiplex streams to the MP4 container -or - to demultiplex streams from an existing MP4 file. The updated mp4...
资源来自pypi官网。 资源全名:pytest_markers_presence-0.6.3-py2.py3-none-any.whl
资源来自pypi官网。 资源全名:pytest_markers_presence-0.4.0-py2.py3-none-any.whl
python库,解压后可用。 资源全名:pytest_markers_presence-0.4.0-py2.py3-none-any.whl
Diagnosing CAD: additional markers from myocardial perfusion SPECT.pdf
react使用高德地图react-amap:Map、Markers、Circle、ContextMenu、自定义ContextMenu
:world_map: 适用于Android的Google Maps Chart 一个Google Maps Android库,用于将标记簇呈现为在Google Maps Android上按指定值分类的图表。 可用图表:,和 安装 确保您的存储库列表中包含JCenter: ... 注意
关于从mapcrafter_markers一个包装 ( ),增加了: 玩家位置命名实体位置(例如:带有名称标签的生物,比如你的马) 根据 mapcrafter 文档,mapcrafter_markers 将生成一个带有前缀标志位置的 marker_generated.js ...
传单真棒标记Shim 存储库包管理器 : drmonty-leaflet-awesome-markers : drmonty-leaflet-awesome-markers : drmonty/leaflet-awesome-markers : drmonty/leaflet-awesome-markers
如何在地图上绘制数千个标记 问题 在地图上有数千个标记时,将鼠标悬停在任何标记上的动画将很慢。 这不是因为javascript,而是因为浏览器无法快速呈现它们。 所有这些图层合成事件都变得太慢而无法显示任何单个动画...
- Improvement: TPolyline -> added Icon property to define the line of polyline. - Improvement: TGMRectangle -> modified all Set and ShowElements methods to use the new method ChangeProperties ...
video.js 进度条指定时间预览图
curly bracket had no apostrophe at the end; that caused an error when reading. (fixed TPropList.SavePropValue for the ptSimple type). - ADD: In the module FlexUtils added the constant BooleanWords -...