Tenho uma dúvida aqui desse exemplo que não funciona não sei pq?
Alguem pode me ajudar?
O erro ocorre nos add e no toArray…
Deve ser uma coisa mto bobo, e não sei pq de erro…
Obrigado
import java.util.*;
public class ArrayList {
public static void main(String[] args) {
ArrayList lista = new ArrayList();
lista.add("Dinardo");
lista.add("Rosa");
lista.add("Rafael");
lista.add("Anderson");
lista.add("Alex");
String colegas[] = (String[])lista.toArray(new String[0]);
for (int i = 0; i < colegas.length; i++) {
System.out.println(colegas[i]);
}
}
}
java.lang.Error: Unresolved compilation problems:
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method toArray(String[]) is undefined for the type ArrayList
at ArrayList.main(ArrayList.java:5)
Exception in thread “main”
Então Daniels não entendi???
Declarei certo ou não?
Ou tenho que criar um método?
java.lang.Error: Unresolved compilation problems:
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method add(String) is undefined for the type ArrayList
The method toArray(String[]) is undefined for the type ArrayList
at ArrayList.main(ArrayList.java:5)
Exception in thread “main” [/quote]
Já existe uma classe ArrayList no pacote java.util entao mude o nome da Classe…
Deixa eu falar uma coisa…
estava fazendo um trabalho em JSP usando o tomcat e tive que mudar o classpath da minha maquina para mostrar o caminho dos
conectores jdbc e o jtdr para conectar com o banco de dados mas antes disso o eclipse tava tudo serto mostrando o caminho “C:\j2sdk 1.4.2_13\bin”
mudei para os conectores do jsp.
Então fui rodar o eclipse deu pau ai lembrei do classpath e mudei para o que estáva antes “C:\j2sdk 1.4.2_13\bin”
Será que não é isso que esta dando pau? Por cauda do classpath?
Por que no mesmo pacote havia um arquivo ArrayList.class compilado. Como não precisa importar a classe explicitamente, ficou subentendido que a classe não existia.
Da próxima vez escolha bem o nome das classes que você dá para não conflitar com classes da API.