SQLite数据库中的逻辑错误,无法找到此类列

时间:2014-07-31 17:34:42

标签: java android sqlite

我的logcat文件: 07-31 22:26:38.600: E/AndroidRuntime(375): FATAL EXCEPTION: main 07-31 22:26:38.600: E/AndroidRuntime(375): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.snotes/com.example.snotes.SHow}: android.database.sqlite.SQLiteException: no such column: _idmoneyreasonDAte: , while compiling: SELECT _idmoneyreasonDAte FROM MONEY_TABLE 07-31 22:26:38.600: E/AndroidRuntime(375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:99) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:123) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-31 22:26:38.600: E/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method) 07-31 22:26:38.600: E/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:521) 07-31 22:26:38.600: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-31 22:26:38.600: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-31 22:26:38.600: E/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method) 07-31 22:26:38.600: E/AndroidRuntime(375): Caused by: android.database.sqlite.SQLiteException: no such column: _idmoneyreasonDAte: , while compiling: SELECT _idmoneyreasonDAte FROM MONEY_TABLE 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46) 07-31 22:26:38.600: E/AndroidRuntime(375): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)

我的java文件``

  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
   import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteDatabase.CursorFactory;
  import android.database.sqlite.SQLiteOpenHelper;

  public class SAve { 
      public static final String KEY_ID ="_id";
      public static final String KEY_MONEY ="money";
      public static final String KEY_REASON ="reason";
      public static final String KEY_DATE ="DAte";

      private static final String DATABASE_NAME ="SAVEdb";
      private static final String DATABASE_TABLE ="MONEY_TABLE";
      private static final int DATABASE_VERSION =1;


      private dbHelper ourHelper;
      private Context ourContext;
      private SQLiteDatabase ourDatabase;

      private static class dbHelper extends SQLiteOpenHelper{

        public dbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase arg0) {
            arg0.execSQL("CREATE TABLE "+ DATABASE_TABLE +" ("+ KEY_ID+" INTEGER   
         PRIMARY KEY AUTOINCREMENT, " +KEY_MONEY
                    +" TEXT NOT NULL, "+ KEY_REASON+" TEXT NOT NULL, "+KEY_DATE+" TEXT         

         NOT NULL); "
                    );
            // TODO Auto-generated method stub

        }

        @Override
        public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {

            arg0.execSQL("DROP TABLE IF EXISTS"+DATABASE_TABLE);
            onCreate(arg0);
            // TODO Auto-generated method stub

        }

      }
 public SAve (Context c){
     ourContext = c;
 }

 public SAve open() throws SQLException{
     ourHelper = new dbHelper(ourContext);
     ourDatabase = ourHelper.getWritableDatabase();
     return this;
 }



 public void close(){
     ourHelper.close();
 }

public long creatEntry(String money, String reason, String daTe) {
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_MONEY, money);
    cv.put(KEY_REASON, reason);
    cv.put(KEY_DATE, daTe);
    return ourDatabase.insert(DATABASE_TABLE, null, cv);
}

public String getData() {
    // TODO Auto-generated method stub
    String[] columns= new String[]{ KEY_ID  + KEY_MONEY + KEY_REASON + KEY_DATE  };
    Cursor c= ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result ="";

    int irow = c.getColumnIndex(KEY_ID);
    int imoney = c.getColumnIndex(KEY_MONEY);
    int ireason = c.getColumnIndex(KEY_REASON);
    int idate = c.getColumnIndex(KEY_DATE);

    for(c.moveToFirst(); c.isAfterLast() ; c.moveToNext()){
        result = result + c.getString(irow)+ " " + c.getString(imoney) + " " +     
       c.getString(ireason) + " " + c.getString(idate)+ "\n";

    }

    return result;
}

}``

虚拟文字 cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk

cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk

cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk v cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk cldslcnlsdncksddddddddddddddddddddddddddddddddddddddddddsdvksadkvbsvbskdvsdvbklsdbvlsbdkvlsbadvklbsadj SK nskd vkjbvksbvklsbdkjvlskvbskdvbksbv.sabvk

1 个答案:

答案 0 :(得分:1)

SQLiteException: no such column: _idmoneyreasonDAte: 
[...] while compiling: SELECT _idmoneyreasonDAte FROM MONEY_TABLE

您正在选择表格_idmoneyreasonDAte中不存在的列的所有值(称为MONEY_TABLE)。

错误在这里:

public String getData() {
    // TODO Auto-generated method stub
    String[] columns= new String[]{ KEY_ID  + KEY_MONEY + KEY_REASON + KEY_DATE  };
    Cursor c= ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

您正在联接KEY_ID + KEY_MONEY + KEY_REASON + KEY_DATE,实际上是"_idmoneyreasonDAte"

好笑,我喜欢它。