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;



public class MainActivity extends AppCompatActivity {

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

 private DatabaseHelper mDBHelper;
 private SQLiteDatabase mDb;

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

 try {
 } 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);
 while (!cursor.isAfterLast()) {
 product += cursor.getString(1);
 gono += cursor.getString(2);


 final String finalGono = no;

 editText.setOnKeyListener(new View.OnKeyListener() {

 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))

 return false;

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

March 23rd 20 at 19:44
0 answer

Find more questions by tags SQLiteJava