Results 1 to 2 of 2
- 07-25-2007, 09:24 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 26
- Rep Power
- 0
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
I've started learning java and I have a problem executing this,
Java Code:public class IfDemo { public static void main(String [] args) { int x = Integer.parseInt(args[0]); double half = 0.0; if(x!=0) { half = x/2.0; System.out.println(x+"/2="+half); } if(x==0) { System.out.println("Nothing found."); } int y = x*5; char grade ='F'; if(y >= 85) { grade='A'; } if(y>=70 &&y<85) grade='c'; System.out.println("y= "+y+" and grade = "+grade); } }
Java Code:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at IfDemo.main(IfDemo.java:7)
- 07-25-2007, 10:55 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 55
- Rep Power
- 0
args[0] is null. if running from the command line are you passing in a value for arg[0] which gets assigned to x. if running from within an ide, such as eclipse, open up the run menu and pass a value to the program. if you can't do that, comment out int x = Integer.parseInt(args[0]) and change it to x = 3 (or some value).
Similar Threads
-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By paul in forum New To JavaReplies: 8Last Post: 03-05-2011, 03:53 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
Exception in thread "main" java.lang.NoClassDefFoundError
By carl in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:26 AM -
Exception in thread "main" java.lang.NoClassesDefFoundError
By tommy in forum New To JavaReplies: 1Last Post: 07-31-2007, 01:54 PM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM
Bookmarks