Erro The application CadastrAluno (process br.com.cadastro) has stopped unexpectedly. Please try again.
Classe AlunoDAO
public class AlunoDAO extends SQLiteOpenHelper {
private static final String DATABASE = "NomeDoBanco" ;
private static final int VERSAO = 1;
private static final String TABELA = "Alunos";
public AlunoDAO(Context ctx) {
super(ctx, DATABASE, null, VERSAO);
}
@Override
public void onCreate(SQLiteDatabase database) {
String sql = "CREATE TABLE " + TABELA + " ("
+ "id INTEGER PRIMARY KEY, "
+ "nome TEXT UNIQUE NOT NULL, "
+ "telefone TEXT, "
+"endereco TEXT, "
+"site TEXT, "
+"nota REAL, "
+"caminhoFoto TEXT"
+");";
database.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS " + TABELA + ";";
database.execSQL(sql);
onCreate(database);
}
public void insere(Aluno aluno) {
ContentValues cv = new ContentValues();
cv.put("nome", aluno.getNome());
cv.put("site", aluno.getSite());
cv.put("endereco", aluno.getEndereco());
cv.put("telefone", aluno.getNota());
cv.put("caminhoFoto", aluno.getCaminhoFoto());
getReadableDatabase().insert(TABELA, null, cv);
}
public List<Aluno> getLista() {
ArrayList<Aluno> alunos = new ArrayList<Aluno>();
String sql= "SELECT * FROM " + TABELA + ";";
Cursor c = getReadableDatabase().rawQuery(sql, null);
while(c.moveToNext()){
Aluno aluno = new Aluno();
aluno.setId(c.getLong(c.getColumnIndex("id")));
aluno.setNome(c.getString(c.getColumnIndex("nome")));
aluno.setSite(c.getString(c.getColumnIndex("site")));
aluno.setEndereco(c.getString(c.getColumnIndex("endereco")));
aluno.setTelefone(c.getString(c.getColumnIndex("telefone")));
aluno.setNota(c.getDouble(c.getColumnIndex("nota")));
aluno.setCaminhoFoto(c.getString(c.getColumnIndex("caminhoFoto")));
alunos.add(aluno);
}
return null;
}
}