Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 试图只显示时间_Android_Sqlite - Fatal编程技术网

Android 试图只显示时间

Android 试图只显示时间,android,sqlite,Android,Sqlite,我试图使用sqlite在Datetime变量中选择时间,但它不起作用,它显示了这个错误 java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.database.CursorWindow.nativeG

我试图使用sqlite在Datetime变量中选择时间,但它不起作用,它显示了这个错误

java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        at android.database.CursorWindow.nativeGetString(Native Method)
        at android.database.CursorWindow.getString(CursorWindow.java:451)
        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
        at com.nextinnovation.pt.barcodescanner.adapter.NewsAdapter.onBindViewHolder(NewsAdapter.java:85)
        at com.nextinnovation.pt.barcodescanner.adapter.NewsAdapter.onBindViewHolder(NewsAdapter.java:25)
这是我的方法:

    public Cursor getDate(Product produit){
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("select time(created_at) from " + TABLE_PRODUCT, null);
        return res;
    }
这就是我所说的:

Cursor date = db.getDate(mData.get(position));
        if (date.moveToFirst()){
            do{
                data = date.getString(date.getColumnIndex("created_at"));
                newsViewHolder.tv_date.setText(data);
                // do what ever you want here
            }while(date.moveToNext());
        }
        date.close();

在SQLite中,可以使用
strftime()

请注意,您需要为表达式返回的列设置别名,以便以后可以按名称访问该列:

Cursor res = db.rawQuery(
    "select strftime('%H:%M:%S', created_at) as created_at from " + TABLE_PRODUCT, 
    null
);

谢谢,但请告诉我时间和日期,例如:昨天12点,我该怎么做?
Cursor res = db.rawQuery(
    "select strftime('%H:%M:%S', created_at) as created_at from " + TABLE_PRODUCT, 
    null
);