Erro no método do java 5

3 respostas
E

Estou fazendo uma classe dao, embora o metodo do java 5 estar dando problemas segundo o erro na linha "public List<Contato> getListaNome() throws SQLException ":

Exception in thread main java.lang.Error: Unresolved compilation problems:

The type List is not generic; it cannot be parameterized with arguments <Contato>

Syntax error, parameterized types are only available if source level is 5.0

The type List is not generic; it cannot be parameterized with arguments <Contato>

Syntax error, parameterized types are only available if source level is 5.0

The type ArrayList is not generic; it cannot be parameterized with arguments <Contato>

Syntax error, parameterized types are only available if source level is 5.0

lista cannot be resolved
at br.com.caelum.jdbc.ContatoDAO.&lt;init&gt;(ContatoDAO.java:33)
at br.com.caelum.jdbc.TesteInsere.main(TesteInsere.java:25)

CODE:

package br.com.caelum.jdbc;

import java.awt.List;

import java.sql.<em>;

import java.util.ArrayList;

import java.util.</em>;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;

public class ContatoDAO {

private Connection connection;

public ContatoDAO() throws SQLException
{
	this.connection = ConnectionFactory.getConnection();
}

public void inseri(Contato contato) throws SQLException
{
	String gravaContatos = "INSERT CONTATOS(NOME, EMAIL, ENDERECO) VALUES(?, ?, ?)";
	PreparedStatement stmt = (PreparedStatement) this.connection.prepareStatement(gravaContatos);
	
	stmt.setString(1, contato.getNome().toString());
	stmt.setString(2, contato.getEmail().toString());
	stmt.setString(3, contato.getEndereco().toString());
	
	//executa
	stmt.execute();
	stmt.close();
}

[b]public List&lt;Contato&gt; getListaNome() throws SQLException 
{
	String strContatos = "SELECT * FROM CONTATOS";
	PreparedStatement stmt = (PreparedStatement) this.connection.prepareStatement(strContatos);
	ResultSet rs = (ResultSet) stmt.executeQuery();
	
	List&lt;Contato&gt; list = new ArrayList&lt;Contato&gt;(); 
	
	
	return lista;
}[/b]

}

3 Respostas

C

Tu deverias usar uma java.util.List e não uma java.awt.List.

furutani

Compile o fonte sem o import java.awt.List e veja se funciona

Paulo_Silveira

o eclipse sem duvida esta reclamando de uma linha ai (xizinho em vermelho)

delete o import do java.awt.List como falaram, e depois clique na lampadinha amarela que vai aparecer na sua declaracao de List e escolha para importar java.util.List, ou entao pressione CONTROL SHIFT O

Criado 14 de outubro de 2006
Ultima resposta 15 de out. de 2006
Respostas 3
Participantes 4