Results 1 to 7 of 7
  1. #1
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Unhappy what is ArrayIndexOutOfBoundsException ???

    this is my program -


    Java Code:
    public class UniqueValue {
    
    	public static void main(String args[]) {
    	
    		
    		int i,x=0;
    		boolean z=false;
      		for (i=0;i<args.length;i++)
    		x=Integer.parseInt (args[i]);
      		{
    			if (args[0] != args[i])
    				z=true;
    			else
    				z=false;
    					
    
      		}
    		if (z=false)
    		System.out.println (x+" is not unique in it's set.");
    		else
    		System.out.println (x+" is  unique in it's set.");
    	}
    
    }



    this is the error message

    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    	at UniqueValue.main(UniqueValue.java:13)

    PLEASE TELL ME HOW TO REMOVE THIS EXCEPTION.
    Last edited by JosAH; 07-15-2011 at 07:54 PM. Reason: removed all the silly font and boldface tags.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Don't use all the special formatting in your posts. Somewhere in your code you are indexing into the array improperly. If you index either below 0 or above the length of the array you will receive this exception. Try to find where the incorrect indexing is.

    Your loop is also a little odd, it only does the first line.

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Holy giant invisible spaghetti monster in the sky who feeds us with his noodly goodness. Why is your text so big, I can't even read whats going on in here with my hugely sized 9" screen.

    Your loop is brokeded, just like Sunde said. Try fixing that, I bet that is one of your indexoutofbounds errors. Now how are you running this? What args are you giving it when you run the program?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Java Code:
    if (args[0] != args[i])
    This looks like your error, try printing the value of i right before this if.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    @OP: I cleaned up your post and removed those huge fonts and boldface tags; don't do that anymore; just using code tags here and there is enough.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    error removed
    Java Code:
    public class UniqueValue {
    
    	public static void main(String args[]) {
    	
    		
    		int i,x=0;
    		boolean z=false;
      		for (i=0;i<args.length;i++)
    		{
                            x=Integer.parseInt (args[i]);
      			if (args[0] != args[i])  //args[i] was not accessable in your code
    				z=true;
    			else
    				z=false;
    					
    
      		}
    		if (z=false)
    		System.out.println (x+" is not unique in it's set.");
    		else
    		System.out.println (x+" is  unique in it's set.");
    	}
    
    }
    after reading your program i think you wanted to make program in which duplicate no should be pinted out
    i modefied code
    Java Code:
    public class ue {
    
    	public static void main(String args[]) {
    	
    		
    		int i;
    		int x[]=new int[args.length];
    		boolean z=false;
      		for (i=0;i<args.length;i++)
    		{	x[i]=Integer.parseInt(args[i]);
    		scan:	for(int j=0;j<i;j++)
      			{
    				if (x[j]==x[i])
    					z=true;
    					break scan;
    				
    					
    			}
    		     
      		
    		if (z)
    		System.out.println (x[i]+" is not unique in it's set.");
    		else
    		System.out.println (x[i]+" is  unique in it's set.");
    		}
    	}
    
    }

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2011, 08:28 PM
  2. ArrayIndexOutOfBoundsException: 0
    By mxsar in forum New To Java
    Replies: 3
    Last Post: 11-16-2010, 10:59 PM
  3. ArrayIndexOutOfBoundsException
    By Corey in forum New To Java
    Replies: 5
    Last Post: 02-02-2010, 01:25 AM
  4. ArrayIndexOutOfBoundsException
    By flaskvacuum in forum New To Java
    Replies: 6
    Last Post: 07-14-2009, 05:36 PM
  5. ArrayIndexOutofBoundsException help
    By filly444 in forum New To Java
    Replies: 9
    Last Post: 09-03-2008, 05:16 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
  •