Results 1 to 6 of 6
- 04-21-2012, 01:44 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
exception in thread main java.lang.arrayindexoutofboundsexception 0
Hi,
i am getting the" exception in thread main java.lang.arrayindexoutofboundsexception 0 " error when i execute the program.
Can some one please help me to resolve it?
here is my program.
class InvertTriangle{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
while(num > 0){
for(int j=1;j<=num;j++){
System.out.print(" "+num+" ");
}
System.out.print("\n");
num--;
}
}
}
- 04-21-2012, 02:13 PM #2
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: exception in thread main java.lang.arrayindexoutofboundsexception 0
You need to look at the syntax of your code. You have some problems, pretty basic, but totally incorrect. Start here:The Java™ Tutorials
- 04-21-2012, 02:40 PM #3
Re: exception in thread main java.lang.arrayindexoutofboundsexception 0
Why do they call it rush hour when nothing moves? - Robin Williams
- 04-21-2012, 02:45 PM #4
Re: exception in thread main java.lang.arrayindexoutofboundsexception 0
You need to check if the array: args is empty before trying to get at its contents.
If you don't understand my response, don't ignore it, ask a question.
- 04-22-2012, 04:37 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Re: exception in thread main java.lang.arrayindexoutofboundsexception 0
I am sorry i did not understand what you are telling as i am new to java.
can you please correct my code and tell where i did a mistake?
Thanks,
- 04-22-2012, 04:59 PM #6
Re: exception in thread main java.lang.arrayindexoutofboundsexception 0
Did Find the code where the exception occurs? Please copy the statement here if you have questions about it.
What array is used in that statement?
Test the length of the array using the .length attribute to see if the array is empty: length > 0.
If the length is 0 do not try to get any elements from the array. Use an if statement to test and skip using the array if it is empty.If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
By dwill19686 in forum New To JavaReplies: 3Last Post: 02-04-2011, 08:31 PM -
exception in thread main java.lang.arrayindexoutofboundsexception
By dwill19686 in forum New To JavaReplies: 3Last Post: 02-03-2011, 04:49 PM -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at wee
By Azaz in forum New To JavaReplies: 4Last Post: 02-02-2011, 04:32 AM -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 102
By dark_metal in forum New To JavaReplies: 5Last Post: 04-05-2010, 02:28 PM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks