2024年1月18日发(作者:)
"": class Test2 is public; should be declared in a file
named at line 3, column 1
错误解释:
"": 类Test2是公共类,应该在名为的文件中被宣告 3行1列处
解决方案:
1、修改类名或文件名,保证两者一致
//////////////////////////////////////////
错误提示:
"": cannot resolve symbol: class Connection in class
1 at line 5, column 5
错误解释:
"": 不能识别的标志(类):在类1中的类Connection 5行5列处
可能原因:
1、没有引包,如.*
2、Connection类名拼写错误
//////////////////////////////////////////
错误提示:
"": incompatible types;found : int,required:
at line 6, column 16
错误解释:
"": 数据类型矛盾;发现:int,要求:String 6行16列处
可能原因:
1、声明类型与赋值类型不一致
2、方法声明的返回类型与实际的返回类型不一致
3、所调用方法的返回类型与方法调用处的接受变量类型不一致
//////////////////////////////////////////
错误提示:
"": cannot resolve symbol: variable a1 in class
1 at line 7, column 24
错误解释:
"": 不能识别的标志(变量):在类1中的变量a1 7行24列处
可能原因:
1、变量未声明
2、变量名拼写错误
3、在声明的范围之外使用变量,如{}之外
//////////////////////////////////////////
错误提示:
"": cannot resolve symbol: method parserInt
()in class r at line 9, column 21
错误解释:
"": 不能识别的标志(方法):在类r中的方法parserInt() 9行21列处
可能原因:
1、方法名拼写错误
2、方法参数类型不匹配
//////////////////////////////////////////
错误提示:
"": '}' expected at line 13, column 2
错误解释:
"": 期望'}' 13行2列处
可能原因:
1、大括号不匹配
//////////////////////////////////////////
错误提示:
"": unreported exception
otFoundException; must be caught or declared to
be thrown at line 11, column 11
错误解释:
"": 未报告的异常otFoundException;必须被捕获或是被声明抛出 11行11列处
解决方案:
1、用try{}catch(){}捕获异常
2、在方法声明时用throws ...,... 声明该方法抛出异常
特别提示:
为便于程序调试时异常定位,强烈建议在进行异常捕获时打印堆栈信息( tactTrace() )
//////////////////////////////////////////
错误提示:
"": non-static variable info cannot be referenced from a
static context at line 17, column 24
错误解释:
"": 非静态的变量info不能在静态上下文(环境)中引用
17行24列处
解决方案:
1、声明对象调用其静态变量
2、修改方法为非静态方法
//////////////////////////////////////////
错误提示:
"": b is already defined in main([]) at line
19, column 5
错误解释:
"": (变量)b在(方法)main([])中已经被定义
*行*列处
解决方案:
1、修改(变量)名称
//////////////////////////////////////////
错误提示:
"": test() is already defined in 1 at line 25,
column 3
错误解释:
"": (方法)test()在(类)1中已经被定义 *行*列处
解决方案:
1、修改(方法)名称
2、修改(方法)参数,即方法重载
//////////////////////////////////////////
错误提示:
"": Duplicate definition of class 1, defined in
D: and also defined in
D:.
错误解释:
"":重复定义了类1,在与D::中都定义了
解决方案:
1、修改类名
特别提示:
如果修改后仍然提示该错,可以通过删除对应class文件来解决
//////////////////////////////////////////
错误提示:
"": variable d might not have been initialized at line 22,
column 22
错误解释:
"":变量d可能还没有被初始化 *行*列处
可能原因:
1、在某种情况下,有可能使用没有被初始化的变量
特别提示:
[代码]
String a;
int x=1;
if(x>0) a="正数";
n(a);
[修改]
String a=null;
...
//////////////////////////////////////////
错误提示:
"": unreachable statement at line 25, column 5
错误解释:
"": 无法到达的语句 *行*列处
可能原因:
1、死循环导致其后的语句没有可能到达
2、return 语句导致其后的语句没有可能到达
特别提示:
[代码]
int a=1;
if(a>0) {return "正数";}
else {return "非正数";}
//没有可能到达
a=0;
//////////////////////////////////////////
错误提示:
"": missing return statement at line 29, column 23
错误解释:
"": (方法)缺失return语句 *行*列处
解决方案:
1、1、确保(方法)在所有可能下都有return语句,如果声明时不是void
//////////////////////////////////////////
错误提示:
"": Package
D: stated in source
1 does not match directory
D:. at line 1, column 13
错误解释:
"": 类的包声明(package ...)与类实际所处包路径不匹配
*行*列处
解决方案:
1、修改包声明,确保与类实际所处包路径一致
//////////////////////////////////////////
错误提示:
"":
错误解释:
"": 期望标志符 *行*列处
可能原因:
1、标志符不可法,如类名用数字开头
//////////////////////////////////////////
错误提示:
"": call to super must be first statement in constructor at
line 6, column 10
错误解释:
"": 在构造函数中调用父类构造函数super(...)必须位于第一句 *行*列处
解决方案:
1、将语句super(...)位于第一句
//////////////////////////////////////////
错误提示:
"": 'try' without 'catch' or 'finally' at line 20, column 5
错误解释:
"": 'try'缺失'catch' 或 'finally' *行*列处
解决方案:
1、'try'必须与'catch'和'finally'两者中至少其一进行搭配使用
//////////////////////////////////////////
错误提示:
"": illegal character: 65307 at line 4, column 12
错误解释:
"": 非法字符 *行*列处
可能原因:
1、使用了中文的符号,如括号,逗号,分号,冒号等
//////////////////////////////////////////
错误提示:
"": reference to Date is ambiguous; both class
in and class in match at
line 6, column 9
错误解释:
"": 对(类)Date的引用不明确;包中的类与包中的类都与之相配(即两个包中都有该类) *行*列处
解决方案:
1、声明或实例化时使用类全名(即包名+类名),如 d =
new ();
//////////////////////////////////////////
错误提示:
"": cannot resolve symbol: constructor Integer ()in class
r at line 6, column 17
错误解释:
"": 不能识别的标志(构造函数):类r中的构造函数Integer() *行*列处
可能原因:
1、调用构造函数时的参数与其原始定义不一致
//////////////////////////////////////////
Exception: Unable to compile class for
JSP
An error occurred at line: -1 in the jsp file: null
告诉你的已经很明显了,你不懂英语吗?都是你的jsp文件不存在了,看是不是路径错了
Q: 运行javac 为何error:cannot read: 1 error
A: 首先检查文件名的的拼写,大小写是否正确,再看目录是否正确。可以在运行该命令的窗口中dir ,看有无该文件。
Q: 为什么 java HelloWorld 不成功?
经常会发现这样的错误:
sDefFoundError: HelloWorld
Exception in thread "main"
A: 首先可能是你CLASSPATH没有设置正确,请按照上面的那个步骤进行设置。如果你路径设置正确了,请确认你的类名是否正确,JAVA中大小写是区分的,看看你的类名是否正确。
Q: NullPointerException的原因?
A: NullPointerException发生的原因是操作了一个为null的变量,比如使用该为null变量的【.】操作.如
12
File[] fileSet=new File[3];//只是初始化了fileSet数组,并没有初始化各个元素,各个元素现在仍为null.
fileSet[0].exists();//该操作就会造成NullPointerException异常.
Q:为什么编译提示uses or overrides a deprecated API?(或java文件使用或覆盖了已过时的API)
A:From jdk文档 notation Type Deprecated
programmers are discouraged from using, typically because it
is dangerous, or because a better alternative exists. Compilers
warn when a deprecated program element is used or overridden in
non-deprecated code。
Q:为什么编译提示class YourClass(注:你的类名)is pubic,
should be declared in a file named ?
A:有两种情况,只有一个解释。两种情况是:
1 把两个public类放在同一个文件中,这样就会出现该问题。
2 一个文件虽然只有一个公共类,但该文件的名字和public的类名不一致(注意大小写,必须和你的public的类的名字大小写完全一样)。
一个解释也就很清楚了,public类所在的文件名不是“类名+.java”。改正的方法也很明白了,一个java文件中只有一个public类,并且该文件名的大小写和public的类的类名完全一致。
Q:uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
A:和泛型有关。不过只是个Note,你可以不用管它。
在1.5中,使用util中的类时,如List,希望你指定特定的类型,如List
Q:Exception in thread "main"
ndexOutOfBoundsException: 6
A:数组越界,访问数组下标为6的元素时发生的越界异常。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1705552406a1412316.html
评论列表(0条)