Java erro: java.lang.ArrayIndexOutOfBoundsException: 1

error java.lang.arrayindexoutofboundsexception minecraft
java.lang.arrayindexoutofboundsexception: 2
how to handle arrayindexoutofboundsexception in java
java.lang.arrayindexoutofboundsexception 0
exception in thread main'' java lang arrayindexoutofboundsexception
java.lang.arrayindexoutofboundsexception 10
exception in thread "main" java.lang.arrayindexoutofboundsexception: 3
java.lang.arrayindexoutofboundsexception 5

In my program the user inputs a boat name and an argument (boat, args). I am trying to write a conditional that prints different things in the console depending what the user inputs as arg. But I am getting an error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at kristenalbrechtproject8.main.main(
C:\Users\Kristen Albrecht\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 5 seconds)

I know it has something to do with my args array but I am new to java and unsure how to solve this. Thanks in advance.

public class main {


* @param args

* the command line arguments


    public static void main(String[] args) throws FileNotFoundException {

    String filename = "Boats.txt";

    // PrintWriter out;

    ArrayList<String> list = new ArrayList<String>();

    FileReader f = new FileReader(filename);

    Scanner keyboard = new Scanner(f);




    System.out.println("File Contents: " + list);

    System.out.println("Enter boat name (name) or quit: ");

    keyboard = new Scanner(;

    while (keyboard.hasNextLine()) {

        String input = keyboard.nextLine();

    if (input.equalsIgnoreCase("quit")) {



    String[] tokens = input.split(",");

    if (tokens.length != 2) {

        System.out.println("Invalid format, try again");



    String name = tokens[0].trim();

    System.out.printf("%-10s \r\n", name, args);


        System.out.println(name + " found in file");

        if(args[1].equals("power on"))
            System.out.println(name + " power up the boat");
        else if(args[1].equals("power off"))
            System.out.println(name + " turn off the boat");
            System.out.println(name + " command does not exist");


        System.out.println(name + " not found in file");


    System.out.println("Enter boat name (name) or quit: ");

    keyboard = new Scanner(;





Seems to me you are passing just one parameter or even no parameters in the console but you are trying to get parameter at position 1 therefore it results in ArrayIndexOutOfBoundsException.

You need to check how many parameters you have:

if (args.length >= 2) {
    if (args[1].equals("power on")) {
        ... do what you want

Exception in thread "main" java.lang , Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 - Solving Array IndexOutOfBoundsException in Java. If you are  java.lang.ArrayIndexOutOfBoundsException occurs when we try to access an element of an array, with an index that is negative or more than the size of array itself. Usually, one would come across “java.lang.ArrayIndexOutOfBoundsException: 4” which occurs when an attempt is made to access (4+1)fifth element of an array, despite the size of array being less than five.

you are using args[1] in the code. you will have to pass in atleast two args to your program and also remember to put them in quotes as you expect to have space in them, like "power on"

java.lang.ArrayIndexOutOfBoundsException, is thrown to indicate that we are trying to access array element with an illegal index. This exception is thrown when the index is either negative or greater than or equal to the size of the array. Hi, ask responsible persons to check function module output Zrfc_Gr_Gi.For these kind of errors,portal restart may become solution if there is change in data or rfc import.

Every array-index starts with 0. So your first argument lies in args[0]. Also keep in mind that you have to concat "power on" with the quotationmarks, otherwise it will be read as two arguments. But as your error suggests I think you are already doing that.

Java- Exception in thread "main" java.lang.NoClassDefFoundError , How do you stop an array out of bounds exception in Java? When Java console displays the following message, what does it mean ? java.lang.ArrayIndexOutOfBoundsException: 1 >= 0 at java.util.Vector.elementAt(Unknown Source) at cu.a(Unknown Source)

How to prevent 'index out of bound exception', , the best practice is to keep the starting index in such a way that when your last iteration is executed, it will check the element at index i & i-1, instead of checking i & i+1 (see line 4 below). Its probably a mod conflict, but would help if someone in Flan can trace what TypeType.getRecipeElement( does, and why an index of 1 (which I'm guessing means the array has no elements in it, if calling 1 is too large) or what it was expecting.

Common reasons of java.lang.ArrayIndexOutOfBoundsException in , java.lang.ArrayIndexOutOfBoundsException is a runtime exception, so it's a Enter size of int array: 3 Please enter int value at index 0: 1 Please enter int value at 2: 3 Enter array index to get the value: 4 Exception in thread "main" java.lang​. public class ArrayIndexOutOfBoundsException extends java.lang.IndexOutOfBoundsException. Students should understand this error/exception when it occurs in a program. An object of this class is thrown when code accesses an array with an illegal index.

What causes a java.lang.ArrayIndexOutOfBoundsException and , lang.ArrayIndexOutOfBoundsException: length=1; index=1 error because index 1 is invalid here. Why? because index in Java array starts with zero rather than  Description We are getting "java.lang.ArrayIndexOutOfBoundsException: 1" exception in pipeline project during source checkout time. This issue occurs most of the time. Due to this, our Continuous Integration process is affected very much.