<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. java語言

    Java常用的語法錯誤

    時間:2025-02-01 18:08:04 java語言 我要投稿
    • 相關推薦

    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.OnExit());

      中文說明;此處不允許使用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();

      中文說明 不兼容的類型

      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: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 它是屬于抽象類的,不能產生對象。

      3.Main.java:6: Myabstract is abstract; cannot be instantiated

      33. 接口的方法不能有方法體

      4 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修飾(抽象類抽象的東西一定要被繼承)

      45 Integer number too large 定義值(整數)過大

    【Java常用的語法錯誤】相關文章:

    java常見的語法錯誤有哪些09-20

    java常用代碼07-07

    java常用名詞及解釋08-10

    常用java的命令有哪些07-18

    java常用的英語單詞06-08

    java常用快捷鍵06-21

    Java常用英語單詞10-08

    常用Java排序算法詳解09-17

    JAVA常用4種排序方法09-26

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人