내가 JavaBeans 컴퍼넌트을하려고하지만 나에게이 오류 제공 :자바 빈즈 컴포넌트 java.lang.NullPointerException이
Exception in thread "main" java.lang.NullPointerException
at probarcomponente.ProbarComponente.main(ProbarComponente.java:37)
Java Result: 1
구성 요소 :
public class Componente implements Serializable {
private List<Persona> lista;
public Componente() {
}
public class Personas {
List<Persona> lista = new LinkedList<Persona>();
}
public List <Persona> Mostrar() {
try {
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
java.sql.Statement comando = conexion.createStatement();
String sql = "select * from dades_pers";
ResultSet result = comando.executeQuery(sql);
while (result.next()) {
String nif = result.getString(1);
String nom = result.getString(2);
String cognoms = result.getString(3);
String tel = result.getString(4);
Personas p = new Personas();
// Inserción en la lista
p.lista.add(new Persona(nif,nom,cognoms,tel));
}
} catch (SQLException ex) {
System.out.println("Error al mostrar datos");
System.out.println(ex.getMessage());
}
return lista ;
}
}
내가 다른 클래스가 "페르소나"과를 그녀의 속성, 생성자, getter 및 setter.
public class Persona {
private String nif ;
private String nom;
private String cognoms;
private String telf;
public Persona(String nif, String nom, String cognoms, String telf) {
this.nif = nif;
this.nom = nom;
this.cognoms = cognoms;
this.telf = telf;
}
public String getNif() {
return nif;
}
public String getNom() {
return nom;
}
public String getCognoms() {
return cognoms;
}
public String getTelf() {
return telf;
}
public void setNif(String nif) {
this.nif = nif;
}
public void setNom(String nom) {
this.nom = nom;
}
public void setCognoms(String cognoms) {
this.cognoms = cognoms;
}
public void setTelf(String telf) {
this.telf = telf;
}
}
하고 마침내는 컴포넌트를 테스트하는 다른 프로젝트를 생성 ..
의 중복 가능성 [null 포인터 예외 무엇입니까?] (http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception를) 그것은 너무 JDBC와 함께 작동 –