admin 管理员组文章数量: 1086019
2024年3月20日发(作者:html基础教程 排版)
java常见的语法错误有哪些
java常见的语法错误有哪些
Java语言作为静态面向对象编程语言的代表,极好地实现了面向
对象理论,允许程序员以优雅的思维方式进行复杂的编程。那么java
常见的语法错误有哪些?以下仅供参考!
具体如下:
1.变量可能未初始化
错误提示::9: variable i might not have been
initialized
n(i);
中文说明:变量i可能没有赋值就使用了。
例子说明:
int i;
n(i);
2.变量重复定义
错误提示::9: i is already defined in
main([]) int i = 2;
中文说明:变量重复定义了
例子说明:int i = 1; int i = 2;
3. 找不到符号:
:26: cannot find symbol
symbol : variable j
location: class Test6
if(j < 0) {
4. 找不到类的错误
:4: cannot find symbol
symbol : class T1
location: class Main
T1 a = new T1();
5. 找不到方法的错误
:5: cannot find symbol
symbol : method a()
location: class T a.a();
6.找不到类
错误提示::1: class Test1 is public, should be declared
in a file named public class Test1 {
中文说明:test1是公共的,必须在文件中声明
例子说明 :建一个文件为Test;在工具中打开这样写public class
Test11 {}; 就会报这个错误
7 找不到这个类(类名跟文件名不一致)
NoClassDefFoundError: asa (wrong name: ASA)
8. 数组下标越界
ndexOutOfBoundsException: 1
at 2(:30)
at (:6)
9. 字符串下标越界
IndexOutOfBoundsException: String index
out of range: 6
at (:558)
at 3(:41)
at (:7)
10. 空指向E
xception in thread "main" interException
at (:31)
11.空返回值
错误提示::54: 'void' type not allowed here
n(());
中文说明;此处不允许使用void返回值
例子说明:如果声明一个void的方法,那就不能直接输出来
Public static void edit() {}
n(());
12. 缺少返回值
:8: missing return statement
int fan(){}
^
1 error
13. 没有返回值的方法中不需要返回值
:10: cannot return a value from method whose result
type is void return a;
^
1 error
14. 引用的方法入参不对
:66: cannot find symbol
symbol
location: class
File ll = TempFile("let","java","aaa");
15. 缺少形参
del() in e cannot be applied to (int)
16. 无效的方法声明(需要返回类型)
invalid method declaration; return type required
public byteValue(){
17. 要求传入的是数组,却传入了字符串
array required, but found
18 找不到构造方法
:4: cannot find symbol
symbol : constructor T()
location: class T n
ew T();
: method
createTempFile(,,)
19、数字格式化异常
Exception
20. 不兼容的类型
错误提示::41: incompatible types
found : []
required: []
File [] a3 = ();
中文说明:不兼容的类型
21. 非静态方法不能在静态上下文中引用
non-static method cannot be referenced from a static
context
22. 不是静态方法而用静态方式调用(类名。方法)
:5: non-static method fun1() cannot be referenced
from a static context
1();
23. 静态访问非静态(变量)
:5: non-static variable a cannot be referenced from a
static context
a = 1000;
24. 静态访问非静态(方法)
:6: non-static method fun1() cannot be referenced
from a static context
fun1(); // 静态的不能调用非静
25. continue outside of loop
(将continue放在for循环外的时候出现的错误报告)
l start of expression
违反规则的表达(将for循环中第二表达放置于for循环外或内部
时出现的错误报告)
27. :6: unreachable statement
in thread "main"
FormatException: null
不能到达的语句(语句放于continue或break后出现不能到达,
及continue和break后不能有语句)
28 break置于循环语句外:8: break outside switch or
loop
break; ^ 1 error
29- 标识符错误(标识符不合法);
【java常见的语法错误有哪些】
版权声明:本文标题:java常见的语法错误有哪些 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1710912232a579257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论