Compilation error, Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 0

Asked

Viewed 12 times

1

Compiler points out the following error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

Just after points to the if line


public class Pilha extends Lista {
    public Pilha(int tamanho){
this.tamanho=tamanho;
}
    public int[] elementos=new int[this.tamanho];
    public int push(int n){
    for(int i=0;i<this.tamanho;i++){
    if(elementos[i]=='0'){/*aqui*/
    this.insert(i,n);
    System.out.println("Valor inserido");

Also points to function call: pilhaInstance.push(10); Detail:the Compiler only points error when calling the function, otherwise compiles normally. I don’t know what I’m missing because I’m beginner in java but I’m seeing and reviewing this code and I don’t find anything.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.