Boa tarde, estou fazedo inserindo dados com o banco de dados sqlite com o seguinte codigo:
package dti;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
*
* @author vitor
*/
public class Album {
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the ano
*/
public int getAno() {
return ano;
}
/**
* @param ano the ano to set
*/
public void setAno(int ano) {
this.ano = ano;
}
/**
* @return the banda
*/
public String getBanda() {
return banda;
}
/**
* @param banda the banda to set
*/
public void setBanda(String banda) {
this.banda = banda;
}
private int id;
private String nome;
private int ano;
private String banda;
public void cadastrar(int id, String nome, int ano, String banda) {
Conexao conexaoSQLite = new Conexao();
conexaoSQLite.conectar();
String sqlInsert = "INSERT INTO tbl_album ("+ "id,nome,idade)" + "values (?,?,?,?)";
PreparedStatement preparedStatement = conexaoSQLite.criarPreparedStament(sqlInsert);
try {
//inserindo os dados
preparedStatement.setInt(1, id);
preparedStatement.setString(2, nome);
preparedStatement.setInt(3, ano);
preparedStatement.setString(4, banda);
int resultado = preparedStatement.executeUpdate();
//Se resultado for 1 inseriu, senão quer dizer que não inseriu
if (resultado == 1) {
System.out.println("Dados inseridos com sucesso");
} else {
System.out.println("Dados não inseridos!!!!");
}
} catch (SQLException e) {
System.out.println("Dados não inseridos!!!!");
} finally {
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
conexaoSQLite.desconectar();
}
}
}
}
Mas insiste em dar o erro
Exception in thread "main" java.lang.NullPointerException
at dti.Album.cadastrar(Album.java:87)
at dti.Dti.main(Dti.java:31)
O que pode ser feito?