1
Class creating the bank
public class CriaBanco extends SQLiteOpenHelper {
private static final String NOME_BANCO = "lista.db";
private static final int VERSAO_BANCO = 1;
public CriaBanco(Context context) {
super(context, NOME_BANCO, null, VERSAO_BANCO);
}
@Override
public void onCreate(SQLiteDatabase db) {
final String SQL_CRIAR_TABELA = "CREATE TABLE lista_notify (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT "+
"hora_notificacao TEXT NOT NULL"+
"texto_notificacao TEXT NOT NULL)";
db.execSQL(SQL_CRIAR_TABELA);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
Mainactivity.java where the instance of the Criabanco.java class is created.
public class MainActivity extends AppCompatActivity {
private EditText ed_hora_notificacao;
private EditText ed_texto_notificacao;
private CriaBanco mDbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CriaBanco banco = new CriaBanco(this);
}}
Method of entering data into the database
public void cadastrar_periodic(View v){
SQLiteDatabase db = mDbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("hora_notificacao", "Toto");
values.put("texto_notificacao", "Terrier");
long newRowId = db.insert("lista_notify", null, values);
}
Error text that gives
Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
Already tried after that insert calling db.close();
– Hiago Souza
yes, but the mistake continues.
– Demetrius