Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

NullPointerException Program

/**

* Generate NullPointerException.

*

*

*/

public class NullPointerExceptionTest {

/**

* generate null pointer exception

*/

public static void generateException() {

try {

// creating only refernceign with null

NullPointerException nullPointer = null;

// call the method that will genereate exception

nullPointer.toString();

} catch (NullPointerException e) {

System.out.println("Error : NullPointerException");

e.printStackTrace();

}

}

/**

* execution begin from here

*

* @param args

* commandline argument

*/

public static void main(String[] args) {

generateException();

}

}

No comments:

Post a Comment

Followers