title: android.database.sqlite.SQLiteException: near "WHERE": syntax error (Sqlite code 1)
body: <p>I would be grateful if anyone could help with this code</p>
  <p><strong>android.database.sqlite.SQLiteException: near &quot;WHERE&quot;: syntax error (Sqlite code 1): , while compiling: SELECT * FROM  WHERE category = 'B', (OS error - 2:No such file or directory)</strong></p>
  <p><a href="https://i.stack.imgur.com/pnGWb.png" rel="nofollow noreferrer">error from debug</a></p>
  <p>My DbHelper is as following</p>
  <pre><code>public class DbHelper extends SQLiteOpenHelper {
      private static final String DATABASE_NAME = &quot;Quiz.db&quot;;
      private static final String KEY_ID = &quot;id&quot;;
      private static final String KEY_QUES = &quot;question&quot;;
      private static final String KEY_ANSWER = &quot;answer&quot;; //correct option
      private static final String KEY_OPTA= &quot;opta&quot;; //option a
      private static final String KEY_OPTB= &quot;optb&quot;; //option b
      private static final String KEY_OPTC= &quot;optc&quot;; //option c
      private static final String KEY_OPTD= &quot;optd&quot;; //option d
      private static final String KEY_CAT=&quot;category&quot;; //category
      private static final String TABLE_QUEST1 = &quot;questUnit1&quot;;
   
      private SQLiteDatabase dbase;
  
      public DbHelper(Context context) {
          super(context, DATABASE_NAME, null, 1);
      }
  
      public DbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
          super(context, DATABASE_NAME, factory, version);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          dbase=db;
  
          String sql1 = &quot;CREATE TABLE IF NOT EXISTS &quot; + TABLE_QUEST1 + &quot; ( &quot;
                  + KEY_ID + &quot; INTEGER PRIMARY KEY AUTOINCREMENT, &quot; + KEY_QUES
                  + &quot; TEXT, &quot; + KEY_ANSWER+ &quot; TEXT, &quot;+KEY_OPTA +&quot; TEXT, &quot;
                  +KEY_OPTB +&quot; TEXT, &quot;+KEY_OPTC+&quot; TEXT, &quot;+KEY_OPTD+&quot; TEXT, &quot;+KEY_CAT+&quot; TEXT)&quot;;
          db.execSQL(sql1);
          addQuestionsUnit1();
  
      }
  
          private void addQuestionsUnit1() {
              QuestionUnit1 q101 = new QuestionUnit1(&quot;What is the decimal equivalent of the binary number 10111&quot;,&quot;21&quot;,&quot;23&quot;,&quot;39&quot;,&quot;42&quot;,&quot;23&quot;,&quot;B&quot;);
              this.addQuestionsUnit1(q101);
              QuestionUnit1 q102 = new QuestionUnit1(&quot;In order to write on a floppy disk with your IBM PC, you must first&quot;,&quot;digitize it&quot;,&quot;format it&quot;,&quot;compile it&quot;,&quot;hardware it&quot;,&quot;format it&quot;,&quot;B&quot;);
              this.addQuestionsUnit1(q102);
      
      QuestionUnit1 q249= new QuestionUnit1(&quot;Firewalls are used to protect against&quot;,&quot;Unauthorized Attacks&quot;,&quot;Viruses&quot;,&quot;Fire Attacks&quot;,&quot;Data Driven Attacks&quot;,&quot;Unauthorized Attacks&quot;,&quot;E&quot;);
              this.addQuestionsUnit1(q249);
              QuestionUnit1 q250= new QuestionUnit1(&quot;The first Digital Computer introduced, was named as &quot;,&quot;UNIVAC&quot;,&quot;EDSAC&quot;,&quot;ENIAC&quot;,&quot;MARK-1&quot;,&quot;MARK-1&quot;,&quot;E&quot;);
              this.addQuestionsUnit1(q250);
      
          }
  
      public void addQuestionsUnit1(QuestionUnit1 quest) {
          //SQLiteDatabase db = this.getWritableDatabase();
          ContentValues values = new ContentValues();
          values.put(KEY_QUES, quest.getQUESTION1());
          values.put(KEY_ANSWER, quest.getANSWER1());
          values.put(KEY_OPTA, quest.getOPTA1());
          values.put(KEY_OPTB, quest.getOPTB1());
          values.put(KEY_OPTC, quest.getOPTC1());
          values.put(KEY_OPTD, quest.getOPTD1());
          values.put(KEY_CAT,quest.getCATEGORY1());
          // Inserting Row
          dbase.insert(TABLE_QUEST1, null, values);
      }
  
  
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
      }
  
      public List&lt;QuestionUnit1&gt; getAllQuestions1(String tname, String lname)
      {
          List&lt;QuestionUnit1&gt; quesList1 = new ArrayList&lt;QuestionUnit1&gt;();
          String selectQuery1 = &quot;SELECT * FROM &quot; + tname+&quot; WHERE &quot;+KEY_CAT+&quot; = '&quot;+lname+&quot;'&quot;;
          dbase=this.getReadableDatabase();
          Cursor cursor = dbase.rawQuery(selectQuery1, null);
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  QuestionUnit1 quest1 = new QuestionUnit1();
                  quest1.setID1(cursor.getInt(0));
                  quest1.setQUESTION1(cursor.getString(1));
                  quest1.setANSWER1(cursor.getString(2));
                  quest1.setOPTA1(cursor.getString(3));
                  quest1.setOPTB1(cursor.getString(4));
                  quest1.setOPTC1(cursor.getString(5));
                  quest1.setOPTD1(cursor.getString(6));
                  quesList1.add(quest1);
              } while (cursor.moveToNext());
          }
          return quesList1;
      }// end pubic list
  }
  </code></pre>
  <p>the code walks like that a butto to To Exercise Activity</p>
  <pre><code>if(position == 2){
                      Intent i= new Intent(getApplicationContext(),Unit1ExerciseActivity.class);
                      i.putExtra(&quot;table_name&quot;,tableName);
                      i.putExtra(&quot;level_name&quot;,&quot;B&quot;);
                      startActivity(i);
                      overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
                  }
  </code></pre>
  <p>and the code in the exercise Activity is</p>
  <pre><code>public class Unit1ExerciseActivity extends AppCompatActivity {
      List&lt;QuestionUnit1&gt; quesList1;
      public int score=0;
      int ctr1=1;
      QuestionUnit1 currentQ1;
      TextView txtQuestion1;
      RadioGroup grp;
      RadioButton rda1, rdb1, rdc1, rdd1;
      Button butNext1;
      Random random1 = new Random();
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      TextView textViewTime1;
      public ArrayList&lt;String&gt; wrongQuestListUnit1 = new ArrayList&lt;String&gt;();
      public ArrayList&lt;String&gt; selectedAnsUnit1 = new ArrayList&lt;String&gt;();
      public ArrayList&lt;String&gt; actualAnswerUnit1 = new ArrayList&lt;String&gt;();
      int number;
      ProgressBar progressBar;
      int progress = 1;
      String tableName=&quot;&quot;,catName=&quot;&quot;;
      TextView qstnNo;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.unit1_exercise_activity);
  
  
          qstnNo = (TextView)findViewById(R.id.qstnNo);
  
          Intent iin=getIntent();
          Bundle b=iin.getExtras();
  
          if(b!=null){
              tableName=(String)b.get(&quot;table_name&quot;);
              catName=(String)b.get(&quot;level_name&quot;);
              Log.d(&quot;Table Name&quot;,tableName);
              Log.d(&quot;Level Name&quot;,catName);
          }
          number=0;
          DbHelper db= new DbHelper(this);
          textViewTime1 = (TextView)findViewById(R.id.textViewTime);
          final CounterClass timer = new CounterClass(1800000, 1000);
          timer.start();
  
          quesList1=db.getAllQuestions1(tableName,catName);
          for(int i=0;i&lt;50;i++){
              while(true){
                  int next = random1.nextInt(50);
                  if(!list.contains(next))
                  {
                      list.add(next);
                      break;
                  }
              }
          }
          currentQ1=quesList1.get(list.get(0));
          txtQuestion1=(TextView)findViewById(R.id.textView1);
          rda1=(RadioButton)findViewById(R.id.radio0);
          rdb1=(RadioButton)findViewById(R.id.radio1);
          rdc1=(RadioButton)findViewById(R.id.radio2);
          rdd1=(RadioButton)findViewById(R.id.radio3);
          butNext1=(Button)findViewById(R.id.button1);
          setQuestionView();
          grp = (RadioGroup) findViewById(R.id.radioGroup1);
          butNext1.setEnabled(false);
          grp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(RadioGroup radioGroup, int i) {
                  if(i== R.id.radio0 || i == R.id.radio1 || i==R.id.radio2 || i == R.id.radio3)
                      butNext1.setEnabled(true);
              }
          });
          progressBar = (ProgressBar) findViewById(R.id.progressBar);
          progressBar.setMax(30);
          progressBar.setProgress(1);
          butNext1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  progress = progress+1;
                  progressBar.setProgress(progress);
                  RadioButton answer = (RadioButton) findViewById(grp.getCheckedRadioButtonId());
                  //Log.d(&quot;yourans&quot;, currentQ1.getANSWER1() + &quot; &quot; + answer.getText());
                  if (currentQ1.getANSWER1().equals(answer.getText())) {
                      score++;
                      //Log.d(&quot;score&quot;, &quot;Your score&quot; + score1);
                  }
                  else
                  {
                      wrongQuestListUnit1.add(number, currentQ1.getQUESTION1());
                      selectedAnsUnit1.add(number, answer.getText().toString());
                      actualAnswerUnit1.add(number, currentQ1.getANSWER1());
                      number++;
                  }
                  grp.clearCheck();
                  butNext1.setEnabled(false);
                  if (ctr1 &lt; 31) {
                      if (ctr1 == 30) {
                          butNext1.setText(&quot;End Test&quot;);
                      }
                      currentQ1 = quesList1.get(list.get(ctr1));
                      setQuestionView();
                  } else {
                      timer.onFinish();
                      timer.cancel();
                  }
              }
          });
  
      }
  
      public class CounterClass extends CountDownTimer {
          public CounterClass(long millisInFuture, long countDownInterval) {
              super(millisInFuture, countDownInterval);
          }
  
          @Override
          public void onTick(long millisUntilFinished) {
              long millis = millisUntilFinished;
              String hms = String.format(&quot;%02d:%02d&quot;,
                      TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                      TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
              textViewTime1.setText(hms);
          }
  
          @Override
          public void onFinish() {
              showResult();
          }
      }
  
      public void showResult(){
          Intent intent = new Intent(Unit1ExerciseActivity.this, ResultActivity.class);
          Bundle b = new Bundle();
          b.putInt(&quot;scoreUnit1 &quot;, score);//Your score
          b.putString(&quot;section&quot;,tableName);//Your table name
          b.putString(&quot;category&quot;,catName);//Your category name
          intent.putStringArrayListExtra(&quot;wrongQuestions&quot;, wrongQuestListUnit1);
          intent.putStringArrayListExtra(&quot;selectedAnswer&quot;, selectedAnsUnit1);
          intent.putStringArrayListExtra(&quot;actualAnswer&quot;, actualAnswerUnit1);
          intent.putExtras(b); //Put your score to your next Intent
          startActivity(intent);
          finish();
      }
  
      private void setQuestionView(){
          txtQuestion1.setText(currentQ1.getQUESTION1());
          rda1.setText(currentQ1.getOPTA1());
          rdb1.setText(currentQ1.getOPTB1());
          rdc1.setText(currentQ1.getOPTC1());
          rdd1.setText(currentQ1.getOPTD1());
          if(ctr1&lt;10)
              qstnNo.setText(&quot;0&quot; + ctr1 + &quot;/30&quot;);
          else
              qstnNo.setText(&quot;&quot; + ctr1+ &quot;/30&quot;);
          ctr1++;
      }
  
      @Override
      public void onBackPressed() {
          //super.onBackPressed();
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          //Uncomment the below code to Set the message and title from the strings.xml file
          //builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);
  
          //Setting message manually and performing action on button click
          builder.setMessage(&quot;If you close all your progress would not be saved... Do you wish to exit ?&quot;)
                  .setCancelable(false)
                  .setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          finish();
                      }
                  })
                  .setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          //  Action for 'NO' Button
                          dialog.cancel();
                      }
                  });
  
          //Creating dialog box
          AlertDialog alert = builder.create();
          //Setting the title manually
          // alert.setTitle(&quot;CompQuiz&quot;);
          alert.show();
      }
  }
  </code></pre>