Error using do while to display random records from database?

When you query from the database in TextViev (text1) the text of the question after answer in EditText to display the following random string of the question, considering the number of correct and incorrect responses using numeric variables ( "a" and "x"). I wrote the following code. Why then after no response loads the text of the following question(in rawQuery product is the text of the question and no - the correct answer stored in the database,which we compare with the entered value using OnKeyListener). Prompt,please,where stumbled.

import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.io.IOException;


public class MainActivity extends AppCompatActivity {

 //Declare the variables of the components
 EditText editText;
 TextView text1;

 private DatabaseHelper mDBHelper;
 private SQLiteDatabase mDb;

@Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R. layout.activity_main);
 mDBHelper = new DatabaseHelper(this);



 try {
mDBHelper.updateDataBase();
 } catch (IOException mIOException) {
 throw new Error("UnableToUpdateDatabase");
}

 try {
 mDb = mDBHelper.getWritableDatabase();
 } catch (SQLException mSQLException) {
 throw mSQLException;
}

 //Find components in XML markup

 text1 = (TextView) findViewById(R. id.text1);
 editText = findViewById(R. id.editText);
 final int[] a = {0};
 final int[] x = {0};
 do {


 String product = "";
 String no = "";


 final Cursor cursor = mDb.rawQuery("SELECT * FROM" + "book1" + "ORDER BY RANDOM() LIMIT 1", null);
cursor.moveToFirst();
 while (!cursor.isAfterLast()) {
 product += cursor.getString(1);
 gono += cursor.getString(2);
cursor.moveToNext();
}
cursor.close();

text1.setText(product);


 final String finalGono = no;

 editText.setOnKeyListener(new View.OnKeyListener() {

@Override
 public boolean onKey(View v, int keyCode, KeyEvent event) {
 if (event.getAction() == KeyEvent.ACTION_DOWN &&
 (keyCode == KeyEvent.KEYCODE_ENTER)) {
 if (editText.getText().toString().equals(finalGono))
a[0]++;
else
x[0]++

}
 return false;
}


});
 } while (a[0] > 2*x[0]);


}
}
March 23rd 20 at 19:44
0 answer

Find more questions by tags SQLiteJava