我在 SQLite 中得到索引越界异常

I am getting index out of bounds exception in SQLite

我正在制作一个精确的单词翻译应用程序。我的 sqlite 和我的应用程序中只有一对单词 returns 当查询精确的文字匹配(逐个字符串)时的结果。 我的问题是当我发出查询时,我在 Android SQLite

中得到一个索引越界异常

android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

然后当我尝试 select 所有记录时它抛出

W/System.err: android.database.CursorIndexOutOfBoundsException: Index 24 requested, with a size of 24

下面是我的代码:

package com.example.android.cebuano_tagalogtranslator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    Button btn_clear;
    Button btn_translate_to_ceb;
    Button btn_translate_to_fil;
    EditText txt_input;
    EditText txt_output;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        //HABAGAT CONTROLS BEGIN
        btn_clear = (Button) findViewById(R.id.btn_clear);
        btn_translate_to_ceb = (Button) findViewById(R.id.btn_trans_to_ceb);
        btn_translate_to_fil = (Button) findViewById(R.id.btn_trans_to_fil);

        txt_input = (EditText) findViewById(R.id.input);
        txt_output = (EditText) findViewById(R.id.output);

        //HABAGAT : CLEAR BOTH TEXT
        btn_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                txt_input.setText("type here");
                txt_output.setText("");
            }
        });

        //HABAGAT : FILIPINO -> CEBUANO
        btn_translate_to_ceb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                try {
                    String textinput = txt_input.getText().toString();
                    textinput = "\""+ textinput +"\"";
                    String filToCebQuery = "SELECT ceb FROM filtoceb WHERE fil = "+ textinput;
                    SQLiteDatabase DB = openOrCreateDatabase("filtoceb", MODE_PRIVATE, null);
                    //Cursor c = DB.rawQuery("SELECT * FROM filtoceb", null);
                    Cursor c = DB.rawQuery(filToCebQuery, null);

                    int cebIndex = c.getColumnIndex("ceb");
                    //int filIndex = c.getColumnIndex("fil");

                    c.moveToFirst();
                    while (c != null) {

                    //Log.i("Results - ceb", c.getString(cebIndex));
                    txt_output.setText(c.getString(cebIndex));
                    c.moveToNext();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });

        //HABAGAT : CREATE DB OPEN IF NOT CREATED YET
            try {
            SQLiteDatabase eventsDB = this.openOrCreateDatabase("filtoceb", MODE_PRIVATE, null);
            //eventsDB.execSQL("drop table user");
            eventsDB.execSQL("CREATE TABLE IF NOT EXISTS filtoceb (fil VARCHAR, ceb VARCHAR)");

            eventsDB.execSQL("INSERT INTO filtoceb (ceb, fil) VALUES ('Kumusta ka?','Kumusta ka?')");
            eventsDB.execSQL("INSERT INTO filtoceb (ceb, fil) VALUES ('Maayo, salamat', 'Mabuti naman, salamat')");
            eventsDB.execSQL("INSERT INTO filtoceb (ceb, fil) VALUES ('Unsay imong pangalan?',  'Ano pangalan mo?')");
            eventsDB.execSQL("INSERT INTO filtoceb (ceb, fil) VALUES ('Unsay ngalan mo?', 'ano pangalan mo?')");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我做错了什么?

int cebIndex = c.getColumnIndex("ceb");

if (cursor.moveToFirst()){
   while(!cursor.isAfterLast()){
      String data = cursor.getString(cebIndex);
      // do what ever you want here
      txt_output.setText(cursor.getString(cebIndex));
      cursor.moveToNext();
   }
}
cursor.close();
if (c!=null)
     {
       try {
            c.moveToFirst();
            while(!c.isAfterLast()){
                 String result = c.getString(c.getColumnIndex("ceb"));
                 txt_output.setText(result);
                 c.moveToNext();
               }
            } 
         finally 
            {
              cursor.close();
             }
      }