Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0 error in Java

前端 未结 8 2066
清酒与你
清酒与你 2021-01-07 05:52

When i tried running this code I get this error..I dont know where i went wrong..

Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException: 0
           


        
8条回答
  •  粉色の甜心
    2021-01-07 05:55

    Are you supplying a command line argument when you run it?

    if (args[0] != null)
        n = Integer.parseInt(args[0]);
    

    If you aren't then the above line will fail. You should check if args.length >= 1 before accessing args[0].

提交回复
热议问题