Home > Java > JavaBase > body text

Common syntax errors in java

angryTom
Release: 2019-11-15 11:03:52
Original
6204 people have browsed it

Common syntax errors in java

Common grammatical errors in java

Grammar errors are problems that do not comply with grammatical rules, such as If you multiply two strings, of course it is wrong. It is what is commonly called a bad sentence.

The following is a list of common grammatical errors in Java. I hope it will be helpful to Java beginners.

1. The variable may not be initialized

Error message:

Abc.java:9: variable i might not have been initialized
                System.out.println(i);
Copy after login

Chinese description: Variable i may be used without assigning a value.

Example description:

int i;
System.out.println(i);
Copy after login

2. Variables are repeatedly defined

Error message:

Abc.java:9: i is already defined in main(java.lang.String[])
                int i = 2;
Copy after login

Chinese description: Variables are repeatedly defined

Example:

 int i = 1;
 int i = 2;
Copy after login

3. Symbol not found:

Test6.java:26: cannot find symbol
symbol  : variable j
location: class Test6
   if(j < 0) {
Copy after login

4. Class not found error

Main.java:4: cannot find symbol
symbol  : class T1
location: class Main
  T1 a = new T1();
Copy after login

5. Method not found error

Main.java:5: cannot find symbol
symbol  : method a()
location: class T
  a.a();
Copy after login

6. Class not found

Error message

Test.java:1: class Test1 is public, should be declared in a file named Test1.java
public class Test1 {
Copy after login

Chinese description test1 is public and must be declared in the file

Example description

Create a file as Test; open it in the tool and write like this public class Test11 { }; This error will be reported

7 The class cannot be found (the class name is inconsistent with the file name)

NoClassDefFoundError: asa (wrong name: ASA)
Copy after login

8. Under the array Subscript out of bounds

java.lang.ArrayIndexOutOfBoundsException: 1
        at Test2.test2(Test2.java:30)
        at Test2.main(Test2.java:6)
Copy after login

9. String subscript out of bounds

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)
Copy after login

10. Null pointer

Exception in thread "main" java.lang.NullPointerException
        at Next.main(Next.java:31)
Copy after login

11 Empty return value

Error message

 Test1.java:54: &#39;void&#39; type not allowed here
   System.out.println(a5.deleteOnExit());
Copy after login

Chinese description; void return value is not allowed here

Example description If a void method is declared, Then it cannot be output directly

  Public static void edit() {}
System.out.println(Test.edit());
Copy after login

12 Missing return value

asa.java:8: missing return statement
 int fan(){}
                  ^
1 error
Copy after login

13 There is no need to return a value in a method without a return value

asa.java:10: cannot return a value from method whose result type is void
   return a;
                        ^
1 error
Copy after login

14. The referenced method has incorrect parameters

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");
Copy after login

15. Missing formal parameters

 del() in sms.service.Service cannot be applied to (int)
Copy after login

16.Invalid Method declaration (return type required)

invalid method declaration; return type required
        public byteValue(){
Copy after login

17. It is required to pass in an array, but a string is passed in

array required, but java.lang.String found
                    ^
Copy after login

18 Constructor method not found

Main.java:4: cannot find symbol
symbol  : constructor T()
location: class T
  new T();
Copy after login

19. Number formatting exception                                                                                        

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();
中文说明 不兼容的类型
Copy after login

20 Integer number too large Definition value (integer) is too large

21. Non-static methods cannot be referenced in a static context

non-static method cannot be referenced from a static context
Copy after login

22. It is not a static method but is called in a static way (class name. method )

Main.java:5: non-static method fun1() cannot be referenced from a static context
                Test.fun1();
Copy after login

23 Static access to non-static (variables)

Test.java:5: non-static variable a cannot be referenced from a static context
                a = 1000;
Copy after login

24. Static access to non-static (methods)

Test.java:6: non-static method fun1() cannot be referenced from a static context
            fun1();                    // 静态的不能调用非静
Copy after login

25.continue outside of loop (error report that occurs when continue is placed outside the for loop)

26.illegal start of expression expression that violates the rules (Error report that occurs when the second expression in the for loop is placed outside or inside the for loop)

27 asa.java:6: unreachable statement Unreachable statement (statement placed inside

cannot be reached after continue or break, and there cannot be statements after continue and break)

28 break is placed outside the loop statement

asa.java:8: break outside switch or loop
 break;
        ^
1 error
Copy after login

29- Identifier error (identifier is illegal);

asa.java:2: <identifier> expected
 int %%;
            ^
1 error
Copy after login

30. The method body was not found or declared abstract ( Method)

MyAbstract.java:6: missing method body, or declare abstract

31. This class is not an abstract class or there is no override. The overridden method fun1() has Abstract methods must be of abstract class

MyAbstract.java:1: MyAdstract is not abstract and does not override abstract method fun1() in MyAdstract
Copy after login

32. Myabstract It belongs to the abstract class and cannot generate objects.

Main.java:6: Myabstract is abstract; cannot be instantiated
Copy after login

33. Interface methods cannot have method bodies

MyInterface.java:2: interface methods cannot have body
Copy after login

34, .It belongs to an abstract class and cannot generate entities

Myabstract is abstract; cannot be instantiated
Copy after login

35. Interface methods cannot have method bodies

interface methods cannot have body
Copy after login

36. Static modification is not allowed here

asa.java:3: modifier static not allowed here
 public static void main(String []args){
     ^    ^
Copy after login

37—Type that cannot be changed (String type cannot be converted to Int type)

asa.java:4: inconvertible types
found   : java.lang.String
required: int
  int b=(int)a;
                           ^
1 error
Copy after login

38.possible loss of precision found: long ;required:byte ; var=varlong Possible loss of precision (loss will be caused when a larger integer is converted to a smaller one, but no loss will be caused when a small integer is converted to a larger one.)

39 delimiter Exception

asa.java:5: &#39;;&#39; expected
Copy after login

40 Bracket Exception

asa.java:8: &#39;}&#39; expected
Copy after login

41. The application attempted to create an array with a negative size.

 java.lang.NegativeArraySizeException
Copy after login

42. Abnormal operation conditions

java.lang.ArithmeticException: / by zero
        at Test2.test(Test2.java:16)
        at Test2.main(Test2.java:5)
Copy after login

43 Abstract methods cannot be modified by final (abstract things of abstract classes must be Inheritance)

44. Abstract methods cannot be modified by private (abstract things in abstract classes must be inherited)

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of Common syntax errors in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!