java罕见语法毛病
语法毛病就是不符合语法划定规矩涌现的题目,比如说你拿两个字符串举行乘法运算,固然就不对了,就是一般所说的病句。
下面为列位整理了java中罕见的语法毛病,愿望对java初学者有所协助。
1.变量能够未初始化
毛病提醒:
Abc.java:9: variable i might not have been initialized System.out.println(i);
中文申明:变量i能够没有赋值就运用了。
例子申明:
int i; System.out.println(i);
2.变量反复定义
毛病提醒:
Abc.java:9: i is already defined in main(java.lang.String[]) int i = 2;
中文申明:变量反复定义了
例子申明:
int i = 1; int i = 2;
3. 找不到标记:
Test6.java:26: cannot find symbol symbol : variable j location: class Test6 if(j < 0) {
4. 找不到类的毛病
Main.java:4: cannot find symbol symbol : class T1 location: class Main T1 a = new T1();
5. 找不到要领的毛病
Main.java:5: cannot find symbol symbol : method a() location: class T a.a();
6. 找不到类
毛病提醒
Test.java:1: class Test1 is public, should be declared in a file named Test1.java public class Test1 {
中文申明 test1是大众的,必须在文件中声明
例子申明
建一个文件为Test;在东西中翻开如许写 public class Test11 {}; 就会报这个毛病
7 找不到这个类(类名跟文件名不一致)
NoClassDefFoundError: asa (wrong name: ASA)
8. 数组下标越界
java.lang.ArrayIndexOutOfBoundsException: 1 at Test2.test2(Test2.java:30) at Test2.main(Test2.java:6)
9. 字符串下标越界
java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.charAt(String.java:558) at Test2.test3(Test2.java:41) at Test2.main(Test2.java:7)
10. 空指向
Exception in thread "main" java.lang.NullPointerException at Next.main(Next.java:31)
11空返回值
毛病提醒
Test1.java:54: 'void' type not allowed here System.out.println(a5.deleteOnExit());
中文申明;此处不允许运用void返回值
例子申明 假如声明一个void的要领,那就不能直接输出来
Public static void edit() {} System.out.println(Test.edit());
12 缺乏返回值
asa.java:8: missing return statement int fan(){} ^ 1 error
13 没有返回值的要领中不须要返回值
asa.java:10: cannot return a value from method whose result type is void return a; ^ 1 error
14. 援用的要领入参不对
Next.java:66: cannot find symbol symbol : method createTempFile(java.lang.String,java.lang.String,java.lang.String) location: class java.io.File File ll = f.createTempFile("let","java","aaa");
15. .缺乏形参
del() in sms.service.Service cannot be applied to (int)
16.无效的要领声明(须要返回范例)
invalid method declaration; return type required public byteValue(){
17. 请求传入的是数组,却传入了字符串
array required, but java.lang.String found ^
18 找不到组织要领
Main.java:4: cannot find symbol symbol : constructor T() location: class T new T();
19、数字格式化非常
Exception in thread "main" java.lang.NumberFormatException: null 20. .不兼容的范例 毛病提醒Test1.java:41: incompatible types found : java.lang.String[] required: java.io.File[] File [] a3 = a11.list(); 中文申明 不兼容的范例
20 Integer number too large 定义值(整数)过大
21. 非静态要领不能在静态高低文中援用
non-static method cannot be referenced from a static context
22.不是静态要领而用静态体式格局挪用(类名。要领)
Main.java:5: non-static method fun1() cannot be referenced from a static context Test.fun1();
23静态接见非静态(变量)
Test.java:5: non-static variable a cannot be referenced from a static context a = 1000;
24. 静态接见非静态(要领)
Test.java:6: non-static method fun1() cannot be referenced from a static context fun1(); // 静态的不能挪用非静
25.continue outside of loop (将continue放在for轮回外的时刻涌现的毛病报告)
26.illegal start of expression 违背划定规矩的表达(将for轮回中第二表达放置于for轮回外或内部时涌现的毛病报告)
27 asa.java:6: unreachable statement 不能到达的语句(语句放于continue或break后出
现不能到达,及continue和break后不能有语句)
28 break置于轮回语句外
asa.java:8: break outside switch or loop break; ^ 1 error
29- 标识符毛病(标识符不合法);
asa.java:2: <identifier> expected int %%; ^ 1 error
30. 没找到要领体,或声明为笼统的(要领)
MyAbstract.java:6: missing method body, or declare abstract
31. 这个类不是笼统类 或许没有掩盖 重写要领fun1() 有笼统的要领的就必须是笼统类
MyAbstract.java:1: MyAdstract is not abstract and does not override abstract method fun1() in MyAdstract
32. Myabstract 它是属于笼统类的,不能发生对象。
Main.java:6: Myabstract is abstract; cannot be instantiated
33. 接口的要领不能有要领体
MyInterface.java:2: interface methods cannot have body
34, .它是属于笼统类的,不能发生实体
Myabstract is abstract; cannot be instantiated
35. 接口的要领不能有要领体
interface methods cannot have body
36. 此处不允许运用static润饰
asa.java:3: modifier static not allowed here public static void main(String []args){ ^ ^
37—不能转变的范例(String 型 不能转换成Int型)
asa.java:4: inconvertible types found : java.lang.String required: int int b=(int)a; ^ 1 error
38.possible loss of precision found: long ;required:byte ; var=varlong 能够形成精度丧失(在整型较大的转换成较小的情况下会形成丧失,小的转大的,则不会形成丧失。)
39分隔符非常
asa.java:5: ';' expected
40 括号非常
asa.java:8: '}' expected
41. 应用程序试图建立大小为负的数组。
java.lang.NegativeArraySizeException
42. 涌现非常的运算前提
java.lang.ArithmeticException: / by zero at Test2.test(Test2.java:16) at Test2.main(Test2.java:5)
43笼统要领不能被final润饰(笼统类的笼统的东西肯定要被继续)
44.笼统要领不能被private润饰(笼统类笼统的东西肯定要被继续)
ki4网,大批的免费Java入门教程,迎接在线进修!
以上就是java罕见语法毛病的细致内容,更多请关注ki4网别的相干文章!