Java错误处理
来自CloudWiki
编译前错误
在编译之前就不通过,显示红线
这通常是由于语法错误、引用了不存在的类或变量引起的,
按照Eclipse提供的错误提示排错即可。
比方说,下面这个错误就是忘了添加对其他类的引用语句,我们添加上即可
错误分类
语法错误
- Syntax error, insert "}" to complete ClassBody
缺少大括号,需插入大括号} 完成类的编写。
- Syntax error on token "}", delete this token
大括号多余,删除这个大括号
变量和类定义错误
- Scanner cannot be resolved to a type
没有引入相关的类
- Duplicate local variable i
变量定义重复
方法定义错误
- Duplicate method main(String[]) in type Main
在类里有两个主方法(main)
- The constructor ** is undefined
构造方法没有定义
- The method ** is undefined
该方法没有定义