Gente, não estou conseguindo criar um banco para minha aplicação.
O que pode estar faltando? obs: já tentei trocar a versão do bd e de nada adiantou.
no momento do findAll dá esse erro:
06-10 13:31:15.870 2222-2222/com.leandro.trabalhofinal E/SQLiteLog: (1) no such table: tarefa
Segue as classes:
public class DatabaseHelper extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "trabalho.db";
private Context context;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE tarefa (_id INTEGER NOT NULL PRIMARY KEY, titulo TEXT NOT NULL, descricao TEXT NOT NULL, pomodoros INTEGER NOT NULL)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE tarefa");
onCreate(db);
}
}
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private Button mMainButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TarefaDao tarefaDao = new TarefaDao(this);
List<Tarefa> tarefas = tarefaDao.findAll();
tarefas.add(new Tarefa(1,"Titulo teste", "Descrição Teste", 4,R.mipmap.ic_launcher));
MyAdapter adapter = new MyAdapter(this, tarefas);
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview);
recyclerView.setLayoutManager(llm);
recyclerView.setAdapter(adapter);
mMainButton = (Button) findViewById(R.id.botao_nova_tarefa);
mMainButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent it = new Intent(MainActivity.this, CadastroActivity.class);
startActivity(it);
}
});
}
}