Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By zFollette

Thread: Array index out of bound error

  1. #1
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Unhappy Array index out of bound error

    i m getting error array index out of bound ...why help me.....
    Error detail is

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at abhiExample.arraytwodiam.main(arraytwodiam.java:27 )

    and program is
    Java Code:
    package abhiExample;
    
    import java.util.Scanner;
    
    public class arraytwodiam {
    
    	public static void main(String [] args)
    	{
    		char[][] Atrace={};
    		int i,j,k,l=0,row ,characters;
    		Scanner in=new Scanner(System.in);
    		char[] ch={'a','b','h','i','s','h','e','k'};
    		int testcase=Integer.parseInt(in.next());
    		for(i=0;i<testcase;i++)
    		{   System.out.println("Enter value of row");
    			row=Integer.parseInt(in.next());
    			System.out.println("Enter value of characters");
    			characters=Integer.parseInt(in.next());
    			System.out.println(row);
    			System.out.println(characters);
    			for(j=0;j<row;j++)
    				for(k=0;k<characters;k++)
    				{   System.out.println("Want to go horizentally");
    		        char cha=in.next().charAt(0);	
    					System.out.println(cha);
    			        if(cha=='y')
    			        Atrace[j][k]=ch[l];
    					else
    				   Atrace[k][j]=ch[l];
    				}
    			l++;
    			for(j=0;j<row;j++)
    				for(k=0;k<characters;k++)
    			      System.out.println(Atrace[j][k]);		
    		}
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default Re: Array index out of bound error

    Quote Originally Posted by codequicker@yahoo.com View Post
    Error detail is

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at abhiExample.arraytwodiam.main(arraytwodiam.java:27 )

    Java Code:
    		char[][] Atrace={};
    What do you think that code snippet does?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Array index out of bound error

    You try to get items out of an array with no items in it. :|

Similar Threads

  1. array index out of bound error
    By anya in forum New To Java
    Replies: 8
    Last Post: 04-27-2012, 09:24 AM
  2. Array Index Out of Bound
    By ankiit in forum New To Java
    Replies: 9
    Last Post: 01-04-2012, 06:03 AM
  3. Array index out of bound exception error
    By rahulkrishnanr in forum Threads and Synchronization
    Replies: 7
    Last Post: 10-12-2010, 05:57 PM
  4. Array index Out of bound Exception
    By nitin_daviet88 in forum New To Java
    Replies: 9
    Last Post: 07-28-2010, 05:32 AM
  5. Array Index Out of bound exception
    By abhijit in forum Networking
    Replies: 7
    Last Post: 09-25-2009, 07:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •