1
I would like to add the text inserted by the user in a vector position, but it is giving error... why?
public static void main(String[] args) {
int cont=0;
String inserida = JOptionPane.showInputDialog("Insira a " +cont+ " String: "
+ "\n 0 encerra.");
String [] vetString = null;
while (!inserida.equals("0")) {
cont++;
vetString[cont] = inserida;
}
//linearString(vetString[], inserida);
}
}
is probably a nullpointer, because you are putting vetstring = null, when creating an array it needs to be initialized, eg: String[] vetString = new String[20];
– Lucas Miranda
Speak, Lucas, I appreciate the help, I did that, but now it continues giving "Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 2 blogat Professor.VetorDeStrings.main(Vetordestrings.java:25) "
– Vinicius Leal
Arrayindexoutofboundsexception means that you are trying to access a vector address that does not exist, if for example you do String[] vetString = new String[20] and then try to access position 22 (vetString[22])
– Lucas Miranda
I figured it was exactly that, but even with the proposal you suggested, the error persists... even to insert the row from position 1 of the Array, even though I declared it with size 10000.
– Vinicius Leal