Java Error “Exception in thread ”main“ java.lang.ArrayIndexOutOfBoundsException”

后端 未结 3 1343
旧巷少年郎
旧巷少年郎 2021-01-26 05:59

Here is this simple code from my book it produces error message in netbeans and in compile version (.class) version running through Command prompt.

Error Message

相关标签:
3条回答
  • 2021-01-26 06:49

    If args[0] is causing an ArrayIndexOutOfBoundsException, then you didn't supply any command-line parameters. Test args.length; if it's 0, then handle the error.

    0 讨论(0)
  • 2021-01-26 06:52

    The args parameter in a class's main method is supplied by command line arguments. You are not invoking the jar with any command line args, so the array has no zero element.

    0 讨论(0)
  • 2021-01-26 06:54

    You are not passing command line arguments. args[0] is expecting a command line argument.

    IF you are running it from command line try this:

    java Intocm 12.0
    

    In eclipse

    Run---> Run Configuration--->
                                Arguments Tab--->
                                                give program arguments-->
                                                                      apply---> run
    
    0 讨论(0)
提交回复
热议问题