Docsity

Common Errors in Java and Their Solutions, Slides of Java Programming

Partial preview of the text

Download Common Errors in Java and Their Solutions and more Slides 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); }