java常見的語法錯誤有哪些
Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程。那麼java常見的.語法錯誤有哪些?以下僅供參考!
具體如下:
1.變量可能未初始化
錯誤提示::9: variable i might not have been initialized
tln(i);
中文説明:變量i可能沒有賦值就使用了。
例子説明:
int i;
tln(i);
2.變量重複定義
錯誤提示::9: i is already defined in main(ng[]) int i = 2;
中文説明:變量重複定義了
例子説明:int i = 1; int i = 2;
3. 找不到符號:
: 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. 數組下標越界
yIndexOutOfBoundsException: 1
at 2()
at (:6)
9. 字符串下標越界
ngIndexOutOfBoundsException: String index out of range: 6
at At()
at 3()
at (:7)
10. 空指向E
xception in thread "main" PointerException
at ()
11.空返回值
錯誤提示:: 'void' type not allowed here
tln(it());
中文説明;此處不允許使用void返回值
例子説明:如果聲明一個void的方法,那就不能直接輸出來
Public static void edit() {}
tln(());
12. 缺少返回值
:8: missing return statement
int fan(){}
^
1 error
13. 沒有返回值的方法中不需要返回值
: cannot return a value from method whose result type is void return a;
^
1 error
14. 引用的方法入參不對
: cannot find symbol
symbol : method createTempFile(ng,ng,ng)
location: class
File ll = teTempFile("let","java","aaa");
15. 缺少形參
del() in ice cannot be applied to (int)
16. 無效的方法聲明(需要返回類型)
invalid method declaration; return type required
public byteValue(){
17. 要求傳入的是數組,卻傳入了字符串
array required, but ng found
18 找不到構造方法
:4: cannot find symbol
symbol : constructor T()
location: class T n
ew T();
19、數字格式化異常
Exception in thread "main" erFormatException: null
20. 不兼容的類型
錯誤提示:: incompatible types
found : ng[]
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循環外的時候出現的錯誤報告)
gal start of expression
違反規則的表達(將for循環中第二表達放置於for循環外或內部時出現的錯誤報告)
27. :6: unreachable statement
不能到達的語句(語句放於continue或break後出現不能到達,及continue和break後不能有語句)
28 break置於循環語句外:8: break outside switch or loop
break; ^ 1 error
29- 標識符錯誤(標識符不合法);
-
全國計算機等級《二級JAVA》命題預測試卷
以下是本站小編帶來的全國計算機等級《二級JAVA》命題預測試卷,歡迎學習!更多內容請關注應屆畢業生考試網!1、軟件生命週期是指()。A.軟件產品從提出、實現、使用維護到停止使用退役的過程B.軟件從需求分析、設計、實現到測試完成的過程,C.軟件的開發過程D.軟件...
-
計算機二級考試Java精選訓練題
下面是應屆畢業生考試網小編搜索整理的計算機二級考試Java精選訓練題,希望對大家有所幫助。[簡答題]本題中,在下畫線上填寫代碼,指定變量b為字節型,變量f為單精度實型,變量l為64位整型。publicclassjaval{publicstaticvoidmain(String[-]args){b=49;f=8.9f;l=0xfedl...
-
Java網絡基礎和Socket通信基礎
導語:Java是一門面向對象編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++裏難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特徵。下面我們來看看Java網絡基礎和Socket通信基礎,希望對大家有所幫助。一、網絡基礎1、InetAddressInetAddres...
-
Java中基於Aspectwerkz的AOP開發
一、AOP編程概覽面向對象編程技術進入軟件開發的主流對軟件的開發方式產生了極大的影響,開發者可以用一組實體以及這些實體之間的關係將系統形象地表示出來,這使得他們能夠設計出規模更大、更復雜的系統,開發週期也比以前更短。OO開發的唯一問題是,它本質上是靜態...