Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default 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);
    }
    
    }
    It compiles fine (I use Jcreator) but when I execute it I get this message :
    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at IfDemo.main(IfDemo.java:7)
    Thanks.

  2. #2
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    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

  1. Replies: 8
    Last Post: 03-05-2011, 04:53 AM
  2. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  3. Replies: 2
    Last Post: 08-01-2007, 06:26 AM
  4. Replies: 1
    Last Post: 07-31-2007, 02:54 PM
  5. Replies: 1
    Last Post: 07-16-2007, 07:32 AM

Posting Permissions

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