I'm developing an application and I needed to put the database SQLite
, after I put it when I open the application it gives an error showing that the application stopped working, I asked my programming teacher he commented that it is a error that happens only at the time of onCreate
of activity
because the rest of the programming is right, it just is not creating onCreate
....
The code I think is giving error would be this part:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_futebol_simples);
and my complete code with the database is this:
public class FutebolSimples extends AppCompatActivity {
private ImageButton imgButton_play, imgButton_pause, imgButton_1, imgButton_2;
private Button vermelho, amarelo;
private TextView txt_valor1, txt_valor2;
private EditText nomeTime1, nomeTime2;
private int contador = 0;
private int contador1 = 0;
private Chronometer reloginho;
long tempoPausado = 0;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_futebol_simples);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
imgButton_1 = (ImageButton) findViewById(R.id.imgButton_1);
imgButton_2 = (ImageButton) findViewById(R.id.imgButton_2);
imgButton_play = (ImageButton) findViewById(R.id.imgButton_play);
imgButton_pause = (ImageButton) findViewById(R.id.imgButton_pause);
reloginho = (Chronometer) findViewById(R.id.chronometer);
txt_valor1 = (TextView) findViewById(R.id.txt_valor1);
txt_valor2 = (TextView) findViewById(R.id.txt_valor2);
nomeTime1 = (EditText) findViewById(R.id.lbl_time1);
nomeTime2 = (EditText) findViewById(R.id.lbl_time2);
vermelho = (Button) findViewById(R.id.btnvermelho);
amarelo = (Button) findViewById(R.id.btnAmarelo);
imgButton_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
contador++;
txt_valor1.setText(" " + contador);
Toast.makeText(getApplicationContext(), "Goooool!!!", Toast.LENGTH_LONG).show();
}
});
imgButton_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
contador1++;
txt_valor2.setText(" " + contador1);
Toast.makeText(getApplicationContext(), "Goooool!!!", Toast.LENGTH_LONG).show();
}
});
imgButton_play.setEnabled(true);
imgButton_pause.setEnabled(false);
imgButton_1.setEnabled(false);
imgButton_2.setEnabled(false);
imgButton_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgButton_play.setEnabled(false);
imgButton_pause.setEnabled(true);
imgButton_1.setEnabled(true);
imgButton_2.setEnabled(true);
reloginho.setBase(SystemClock.elapsedRealtime());
reloginho.start();
reloginho.setBase(SystemClock.elapsedRealtime() + tempoPausado);
}
});
imgButton_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgButton_play.setEnabled(true);
imgButton_pause.setEnabled(false);
imgButton_1.setEnabled(false);
imgButton_2.setEnabled(false);
tempoPausado = reloginho.getBase();
SystemClock.elapsedRealtime();
reloginho.stop();
}
});
db = openOrCreateDatabase("Resultado", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS futebol (TimeOne VARCHAR, TimeTwo VARCHAR, FinalOne INT, FinalTwo INT);");
}
public void saveR (View view){
if(txt_valor1.getText().toString().trim().length()==0 || txt_valor2.getText().toString().trim().length()==0 || nomeTime1.getText().toString().trim().length()==0 || nomeTime2.toString().trim().length()==0 || vermelho.getText().toString().trim().length()==0 || amarelo.getText().toString().trim().length()==0){
Toast.makeText(getApplicationContext(), "Por favor inicia uma partida!", Toast.LENGTH_SHORT).show();
return;
}
db.execSQL("INSERT INTO futebol VALUES('"+txt_valor1.getText()+"','"+txt_valor2.getText()+"','"+nomeTime1.getText()+"','"+nomeTime2.getText()+"','"+vermelho.getText()+"','"+amarelo.getText()+"');");
Toast.makeText(getApplicationContext(), "Partida Salva", Toast.LENGTH_LONG).show();
}
public void listar (View view){
Cursor c = db.rawQuery("SELECT * FROM futebol", null);
if (c.getCount() == 0){
Toast.makeText(getApplicationContext(), "Erro na pesquisa!", Toast.LENGTH_SHORT).show();
return;
}
StringBuffer buffer = new StringBuffer();
while (c.moveToFirst()) {
buffer.append("Nome: "+c.getString(0)+"\n");
}
Toast.makeText(getApplicationContext(), "Resultado com sucesso!", Toast.LENGTH_SHORT);
}
}
The error message that appears when I click the button to call this Activity
is "The AllSports Beta application has stopped." I click Ok and it returns to the application start screen. p>
If someone can help me I'll be very grateful ....