Docsity

Common Errors in Java and Their Solutions, Lecture notes of Java Programming

Partial preview of the text

Download Common Errors in Java and Their Solutions and more Lecture notes Java Programming in PDF only on Docsity!

Common errors in java

๏‚— No class found error

๏‚— No such method error: main

๏‚— Can not resolve symbol

Error:Exception in thread main: No classDeffound error

Error:Exception in thread main:

No classDeffound error

๏‚— Public class CommonErrors

๏‚— Public static void display() ๏‚— { System.out.println(โ€œHelloWorldโ€); ๏‚— }

Exception in thread main:

No such method error

๏‚— Public class CommonErrors

๏‚— Public static void display() ๏‚— { System.out.println(โ€œHelloWorldโ€); ๏‚— } ๏‚— No main method in file

Exception in thread main: No such method error

Can not resolve symbol

๏‚— Very common error

Exception in thread main:

No such method error

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— Int number; System.out.println(number1); ๏‚— }

Variable might not have been

initialized

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— Int number; System.out.println(number); ๏‚— } ๏‚— //value has not been assigned to โ€žnumberโ€Ÿ

Variable might not have been

initialized

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— Int number=10; System.out.println(number); ๏‚— } ๏‚— //value has not been assigned to โ€žnumberโ€Ÿ

Array IndexoutofboundException

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { System.out.println(args[0]); ๏‚— } ๏‚— //args array can only be accessed if command line arguments are provided

Number Format Exception

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— String s=โ€œ20sโ€; ๏‚— Int number=Integer.parseInt(s); }

Number Format Exception

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— String s=โ€œ20โ€; ๏‚— Int number=Integer.parseInt(s); } //this program will be executed now

Error: Null pointer exception

๏‚— Public class CommonErrors

๏‚— Public static void main(String [] args) ๏‚— { ๏‚— Student s=null; ๏‚— System.out.println(s); }