Results 1 to 4 of 4
- 11-16-2010, 08:14 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
ArrayIndexOutOfBoundsException: 0
Hello all!
I have started taking classes in Java some weeks ago and I have come across my first problem... I'm getting this error when I run the programme although during the compiling I have no errors. I'm posting the code and the error so maybe someone can help :confused:
Thank you in advance for your time!
import java.io.*;
class AthroismaApp
{ public static void main(String args[]) throws IOException
{ int a, b;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println();
System.out.print("To athroisma ton "+a+" kai "+b);
System.out.println(" einai iso me "+(a+b));
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at AthroismaApp.main(AthroismaApp.java:5)
- 11-16-2010, 08:17 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 12
Do you know what the args array is? How do you start your application? One hint, the args array holds the arguments when you call your program, eg:
Java Code:java MyApp 1 2 3 4
Also another tip, whenever you're doing something with command line arguments, check the length of the args array, to see if it conforms to your demands before you use it in your code.Ever seen a dog chase its tail? Now that's an infinite loop.
- 11-16-2010, 08:45 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
I got it! We have never used java name parameters before so I didn't know I could put parameters there.
Thank you very much!!! :D
- 11-16-2010, 11:59 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 12
Similar Threads
-
ArrayIndexOutOfBoundsException
By Corey in forum New To JavaReplies: 5Last Post: 02-02-2010, 02:25 AM -
ArrayIndexOutOfBoundsException
By flaskvacuum in forum New To JavaReplies: 6Last Post: 07-14-2009, 06:36 PM -
ArrayIndexOutofBoundsException help
By filly444 in forum New To JavaReplies: 9Last Post: 09-03-2008, 06:16 PM -
ArrayIndexOutOfBoundsException
By daredavil82 in forum New To JavaReplies: 2Last Post: 12-14-2007, 10:29 PM
Bookmarks