0
Inside the Oncreate:
spnMateriasID = (Spinner) findViewById(R.id.spnMateria);
try{
atividadeModel = new AtividadeModel(this);
atividadeModel.getWritableDatabase();
materiaModel = new MateriaModel(this);
materiaModel.getWritableDatabase();
adapterMateria = buscaMaterias(this);
} catch(SQLException ex){
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
}
spnMateriasID.setAdapter(adapterMateria);
public ArrayAdapter<String> buscaMaterias(Context context){
ArrayAdapter<String> materias = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
Cursor dados = conn.query("materias",null, null, null, null, null, null);
if(dados.getCount() > 0){
dados.moveToFirst();
while(dados.moveToNext()){
materias.add(dados.getString(1));
}
}
return materias;
}
Felipe puts more details of the problem in the question. On which line exactly occurs the error?
– gato
This is the error generated when trying to fetch the data and popular the Arrayadapter; Problem is that every time I try to open the connection of some error.
– Felipe
Where the variable is defined
conn
? It seems that it lacks more codes there, puts the error stack tbm.– gato
Caused by: java.lang.Nullpointerexception at com.example.Felipe.tutor.Additionactivity.searches(Additionactivity.java:120) at with.example.Felipe.tutor.Additionactivity.onCreate(Additionactivity.java:61) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) Could Not Do It All
– Felipe
Above Oncreate I have declared: private Sqlitedatabase Conn;
– Felipe
You initialized the variable
conn
? Assign an instance to it?– gato
Our lack of attention. I started Sqlitedatabase Conn and it worked, Thank you so much for helping me out.
– Felipe