Home Java Java-get-example Java error code

Related Tutorials


 
 

Share on Google+Share on Google+

Java error code

Advertisement
Java Error code are the set of error that occurs during the compile-time and Run-time. From java error we have given you a sample of code that makes you to understand the java error code in a better way.

Java error code

     

Java Error code are the set of error that occurs during the compile-time and Run-time. From java error we have given  you a sample of code that makes you to understand the java error code in a better way.

Understand with Example

In this Tutorial we want to describe you a code that help you in understanding a Java error code. For this we have a class name 'Error code'. Inside the main method we have an array list that is used to store when there is a large variation in the amount of data to be taken. The array hold the constant amount of data like number of month in a year, but unlike array list  there is no upper bound for the array list. The list is used to add integer as a wrapper because array list never hold the primitive data in the try block. There is a subsequent a catch block is after the try block to caught the exception occurred in the try block.

On execution the given code, the prompt will show you an Null pointer exception, because we do not specify the size of an array. This result in java error code.

JavaErrorCode

import java.util.*;

public class Errorcode {

  public static void main(String[] args
  {

  ArrayList list = null;
  try {
  list.add(1new Integer(1));
  catch (Exception ex) {
  System.out.println(ex);
  }
  }
}

Output

compile-single:
run-single:
java.lang.NullPointerException
BUILD SUCCESSFUL (total time: seconds)

For removing this runtime error you have to specify the size of the Array.

Download code
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 3, 2008

Related Tutorials

Discuss: Java error code   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com