0

私はかなり詳細に調べましたが、同様の問題を見つけることはできません。

簡単に言えば、特定の日付に入力されたデータベース エントリを取得しようとしています。

これは私が持っているものです

Calendar calendar = Calendar.getInstance(); 
String dateAccessed = (calendar.get(Calendar.DAY_OF_MONTH) + "/" + (calendar.get(Calendar.MONTH)+1) + "/" + calendar.get(Calendar.YEAR));


HashMap<String, String> queryValues = new HashMap<String, String>();

queryValues.put("diaryName", valMealName);
queryValues.put("diaryDate", dateAccessed);
queryValues.put("diaryNumber", Long.toString(carbsValue));
controller.insertDiary(queryValues);

次のようにエントリを保存します

    public void insertDiary(HashMap<String, String> queryValues) {
    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("diaryName", queryValues.get("diaryName"));
    values.put("diaryDate", queryValues.get("diaryDate"));
    values.put("diaryNumber", queryValues.get("diaryNumber"));
    database.insert("diarys", null, values);
    database.close();
}

検索/ LIKE クエリなしで通常の ListView にデータを入力できるため、これがうまく保存されていることはわかっています。

これを行うには、DBController クラスで次のことを試みています

public ArrayList<HashMap<String, String>> searchByDate() {

    ArrayList<HashMap<String, String>> wordList;
    wordList = new ArrayList<HashMap<String, String>>();
    SQLiteDatabase database = this.getReadableDatabase();
    String selectQuery = "SELECT  * FROM diarys";
    Cursor cursor = database.query(selectQuery, new String[] { "diaryId",
            "diaryName", "diaryDate", "diaryNumber" }, "diaryDate LIKE '"
            + dateAccessed + "%'", null, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("diaryId", cursor.getString(0));
            map.put("diaryName", cursor.getString(1));
            map.put("diaryDate", cursor.getString(2));
            map.put("diaryNumber", cursor.getString(3));
            wordList.add(map);
        } while (cursor.moveToNext());
    }
    return wordList;

}

に続く

ArrayList<HashMap<String, String>> diaryList = controller
            .searchByDate();

    ListAdapter adapter = new SimpleAdapter(FoodDiary.this, diaryList,
            R.layout.view_diary_entry, new String[] { "diaryId",
                    "diaryName", "diaryDate", "diaryNumber" }, new int[] {
                    R.id.diaryId, R.id.diaryName, R.id.diaryDate,
                    R.id.diaryNumber });
    setListAdapter(adapter);

私のアクティビティクラスでは

そして、これは私のエラーログです

W/dalvikvm(1013): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.master_zangetsu.netcarbsdiary/com.master_zangetsu.netcarbcalculator.FoodDiary}: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT diaryId, diaryName, diaryDate, diaryNumber FROM SELECT  * FROM diarys WHERE diaryDate LIKE '28/6/2013%'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT diaryId, diaryName, diaryDate, diaryNumber FROM SELECT  * FROM diarys WHERE diaryDate LIKE '28/6/2013%'
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.master_zangetsu.netcarbcalculator.DBController.searchByDate(DBController.java:176)
at com.master_zangetsu.netcarbcalculator.FoodDiary.onCreate(FoodDiary.java:123)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

私はポイントを得るためにいくつかのチュートリアルに従ったので、私が私の深さから外れていると言ってもかなり安全です.

どんな助けでも大歓迎です

4

1 に答える 1