ArrayIndexOutOfBoundsException: Why does 0 occur?

Asked 2 years ago, Updated 2 years ago, 22 views

... import java.util.Scanner;

public class Driver { public static void main(String[] args) {

    Sum sumObject = new Sum();

    int upper = Integer.parseInt(args[0]);
    Thread child = new Thread(new Summation(upper, sumObject));

    child.start();

    try {
        child.join(); 
        System.out.println ("total: " + sumObject.getSum()));
    } } catch (InterruptedException e) {
    }
}

} ...

I'm running the Java thread example above code, but I keep getting errors. Why is that error coming up?

java

2022-09-22 13:21

1 Answers

An error message in question is an exception that occurs when dealing with an array.

The ArrayList or array is created only, but the actual array does not seem to have any values registered.

The code in the question does not contain any code that deals with the array, so please upload the code in the Summation class.


2022-09-22 13:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.