how to handle this java.lang.ArrayIndexOutOfBoundsException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaikhussain
    New Member
    • Sep 2010
    • 1

    how to handle this java.lang.ArrayIndexOutOfBoundsException

    Code:
    public class EmployeeServicesTestCase {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] s)throws Exception {
    		// TODO Auto-generated method stub
    		BeanFactory beans=new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    		EmployeeService es=(EmployeeService)beans.getBean("employeeService");
    		
    		es.incrementSalary(Integer.parseInt(s[0]), 1000);
    	
    
    	}
    
    }




    Exception is:------
    log4j:WARN No appenders could be found for logger (org.springfram ework.util.Clas sUtils).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" java.lang.Array IndexOutOfBound sException: 0
    at com.shaik.sprin g.Test.Employee ServicesTestCas e.main(Employee ServicesTestCas e.java:22)
    Last edited by Niheel; Sep 5 '10, 04:51 PM. Reason: added code tags to code, please use code tags to show code
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    It looks like you are not passing anything in the command line argument.

    To get the arguments you need to run your program as in the below example.

    Code:
    Java MyPrgm arg1 arg2 arg3 arg4
    Now in main you can loop through the command line argument array and get the arguments

    Code:
    public static void main(String args[])
    {
        for (int i = 0; i < args.length; i++)
          System.out.println(args[i]);
    }
    Check this for more information.

    Regards
    Dheeraj Joshi

    Comment

    Working...