第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Android Studio getWritableDatabase(); 導(dǎo)致我的應(yīng)用程序崩潰

Android Studio getWritableDatabase(); 導(dǎo)致我的應(yīng)用程序崩潰

守著一只汪 2021-12-10 15:05:52
所以我一直在嘗試使用該getData()方法進(jìn)行查詢(xún),并且每當(dāng)我運(yùn)行調(diào)試時(shí),我都可以看到它與該dbHelper.getWritableDatabase()行一起崩潰。我以為我是在onCreate()方法中創(chuàng)建數(shù)據(jù)庫(kù),所以我不確定發(fā)生了什么。我的代碼在下面。我將不勝感激任何幫助!public String getData(int firstSelection, int secondSelection, int thirdSelection,                          int fourthSelection, int fifthSelection)    {        SQLiteDatabase db = dbHelper.getWritableDatabase();        String firstSelectionStr, secondSelectionStr, thirdSelectionStr, fourthSelectionStr, fifthSelectionStr;        firstSelectionStr = Integer.toString(firstSelection);        secondSelectionStr = Integer.toString(secondSelection);        thirdSelectionStr = Integer.toString(thirdSelection);        fourthSelectionStr = Integer.toString(fourthSelection);        fifthSelectionStr = Integer.toString(fifthSelection);        String[] columns = {DBHelper.UID,DBHelper.CNAME};        String selectQuery = "SELECT " + DBHelper.CNAME + " FROM "+ "CraftsAppDatabase" + " WHERE First_Attribute=? "                + " AND Second_Attribute=? " + " AND Third_Attribute=? " + " AND Fourth_Attribute=? "                + " AND Fifth_Attribute=? ";        Cursor cursor=db.rawQuery(selectQuery, new String[] {firstSelectionStr, secondSelectionStr, thirdSelectionStr,                            fourthSelectionStr, fifthSelectionStr});        StringBuilder buffer = new StringBuilder();        // Append every data together        while (cursor.moveToNext())        {            String chosenItem = cursor.getString(cursor.getColumnIndex(DBHelper.CNAME));            buffer.append(chosenItem + "/n");        }        return buffer.toString();    }
查看完整描述

2 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊

我終于想通了這一點(diǎn)。這CNAME在下面的命令應(yīng)該是Craft_Name。


db.execSQL("INSERT INTO " + TABLE_NAME + "(CNAME, First_Attribute, Second_Attribute, Third_Attribute, Fourth_Attribute, Fifth_Attribute ) " +

                    "VALUES ('Landscape Drawing', '1', '4','8', 'NONE', 'NONE')");


查看完整回答
反對(duì) 回復(fù) 2021-12-10
?
富國(guó)滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

這是獲取句柄和查詢(xún)的方法:


public DBHelper extends SQLiteOpenHelper {


    private static final String DATABASE_NAME     = "crafts.db"; 

    private static final String TABLE_CRAFT_TOOLS = "craft_tools";

    private static final String KEY_CRAFT_NAME    = "craft_name";


    protected static SQLiteDatabase db = null;


    /** Constructor */

    public SqliteBaseHelper(Context context, String name, CursorFactory factory, int version) {

        super(context, DATABASE_NAME, factory, DATABASE_VERSION);

        if(db == null) {db = getWritableDatabase();}

    }


    /** this method possibly belongs into the helper class */

    public String getString(int firstSelection, int secondSelection, int thirdSelection, int fourthSelection, int fifthSelection) {


        StringBuilder sb = new StringBuilder();


        String sql = "SELECT " + KEY_CRAFT_NAME + " FROM " + TABLE_CRAFT_TOOLS + " WHERE " +

            "First_Attribute=? AND " +

            "Second_Attribute=? AND " +

            "Third_Attribute=? AND " +

            "Fourth_Attribute=? AND " +

            "Fifth_Attribute=? ";


        String[] selectionArgs = new String[] {

            Integer.toString(firstSelection),

            Integer.toString(secondSelection),

            Integer.toString(thirdSelection),

            Integer.toString(fourthSelection),

            Integer.toString(fifthSelection)

        };


        try {

            Cursor cursor = db.rawQuery(sql, selectionArgs);

            if (cursor.moveToFirst()) {

                do {

                    sb.append(cursor.getString(cursor.getColumnIndex(KEY_CRAFT_NAME)) + "/n");

                } while(cursor.moveToNext());

            } else {

                Log.w(LOG_TAG, "no crafts found.");

            }

        } catch (SQLiteException e) {

            Log.e(LOG_TAG, e.getMessage());

        } finally {

            if (! cursor.isClosed()) {

                cursor.close();

            }

        }

        return sb.toString();

    }


    ...

}


查看完整回答
反對(duì) 回復(fù) 2021-12-10
  • 2 回答
  • 0 關(guān)注
  • 474 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)