Results 1 to 15 of 15
  1. #1
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Question Simple Blank Filler project Help

    So I have this code:


    class BlankFiller {
    public static void main(String[] args) {
    System.out.println("The " + args[0]
    + " " + args[1] + " fox "
    + "jumped over the "
    + args[2] + " dog."
    );
    }
    }


    And I have Run > Set Project Configuration > Customize set up with the Class name and arguments filled out, but I still get this error

    run:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at BlankFiller.main(BlankFiller.java:3)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)


    What did I do wrong?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,232
    Blog Entries
    7
    Rep Power
    24

    Default

    Did you pass command line arguments to your program because it expects at least three of them ... I guess you passed none.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    I have this in the arguments field: big fat hairy

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,232
    Blog Entries
    7
    Rep Power
    24

    Default

    See if those arguments make it to your program; add this to the start of your main( ... ) method and see:

    Java Code:
    for (int i= 0; i < args.length; i++)
       System.out.println(i+": "+args[i]);
    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    sunstick is offline Member
    Join Date
    Jul 2011
    Location
    Chicago
    Posts
    1
    Rep Power
    0

    Default

    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0" indicates although you passed 3 arguments to main function, it received none. The exception occurred the very first time you tried to access your argument, i.e, when you tried to read args[0]. I guess you were not using your IDE correctly.

  6. #6
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default


    I get the same error message

  7. #7
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    Thanks, so what do I do?

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,232
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by Idoq View Post
    Thanks, so what do I do?
    Did you try my suggestion? (see reply #4) I bet no arguments were given to your program.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  9. #9
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    Yes, my code looks like this now:

    Java Code:
    class BlankFiller {
        public static void main(String[] args) {
            for (int i= 0; i < args.length; i++)
       System.out.println(i+": "+args[i]);
            System.out.println("The " + args[0]
                    + " " + args[1] + " fox "
                    + "jumped over the "
                    + args[2] + " dog."
           );
        }
    }
    ...and I get the same error message

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,232
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by Idoq View Post
    Yes, my code looks like this now:

    Java Code:
    class BlankFiller {
        public static void main(String[] args) {
            for (int i= 0; i < args.length; i++)
       System.out.println(i+": "+args[i]);
            System.out.println("The " + args[0]
                    + " " + args[1] + " fox "
                    + "jumped over the "
                    + args[2] + " dog."
           );
        }
    }
    ...and I get the same error message
    I guess no arguments were printed ... it indicates that no arguments were passed to your program, so check your IDE's manual how to do that.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  11. #11
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    I am using NetBeans 7.0, do you (or anyone) know anything about this?
    The manual just says filling in the arguments field would pass it to the program

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,232
    Blog Entries
    7
    Rep Power
    24

    Default

    Nope, sorry, I never touched NetBeans; I'm using Eclipse but I'm sure somebody else will jump in. Doesn't NetBeans come with proper online help documentation?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  13. #13
    Idoq is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    Yes but this is all I have found about passing arguments (and I have already done this)

    Arguments. Add arguments to pass to the main class during application execution. Note that arguments cannot be passed to individual files.

  14. #14
    sidthekid316 is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default I got this too

    i got the same exact message....using Netbeans 6.9.1 tho...tried everything listed, and same reseult: error message

  15. #15
    Eve
    Eve is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

Similar Threads

  1. struts-blank.war
    By Dayanand in forum Web Frameworks
    Replies: 2
    Last Post: 08-02-2011, 01:08 PM
  2. Need help with simple java project
    By Jaeela in forum New To Java
    Replies: 2
    Last Post: 03-28-2011, 02:07 AM
  3. Fairly Simple (I think) programming project
    By Glyph in forum Jobs Offered
    Replies: 0
    Last Post: 10-22-2010, 12:16 AM
  4. Simple Project 4 or 5 Hours Pay $100
    By billaaa777 in forum Jobs Offered
    Replies: 0
    Last Post: 08-30-2008, 12:45 AM
  5. [SOLVED] Very Simple 2-3 hour project $50
    By arbit3r in forum Jobs Offered
    Replies: 3
    Last Post: 08-05-2008, 03:20 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
  •