未使用SQLiteOpenHelper创建数据库

时间:2015-11-25 18:54:21

标签: android sqlite android-sqlite

我是Android的新手,我正在学习SQLite数据库。但不知何故,数据库没有使用以下代码创建:

package com.example.sqllitetest;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SQLHelper s = new SQLHelper(this);

}


public class SQLHelper extends SQLiteOpenHelper {



    public SQLHelper(Context c)
    {

        super(c,"test",null,1);


    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL("Create Table TESTING (_id integer primary key,name  text);");
    }

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

    }

}

}

但似乎没有创建数据库“test”。请帮我解决这个问题。 logcat的:

 11-25 23:23:30.824: E/SQLiteLog(28496): (283) recovered 103 frames from WAL file /data/user/0/com.android.providers.media/databases/external.db-wal
 11-25 23:23:33.391: E/msm8974_platform(302): platform_update_tpa_poll: Could not get ctl for mixer cmd - TPA6165 POLL ACC DET
 11-25 23:23:37.351: E/OMX-VDEC-1080P(302): Failed to enable dynamic buffer mode
  11-25 23:23:37.352: E/OMXNodeInstance(302): OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001019
  11-25 23:23:37.352: E/ACodec(302): [OMX.qcom.video.decoder.mpeg4] storeMetaDataInBuffers failed w/ err -2147483648
  11-25 23:23:37.371: E/C2DColorConvert(302): unknown format passed for luma alignment number
  11-25 23:23:37.426: E/C2DColorConvert(302): unknown format passed for luma   alignment number
  11-25 23:23:37.426: E/C2DColorConvert(302): unknown format passed for luma alignment number
  11-25 23:33:14.274: E/PMBA(846): No global metadata in state file!
  11-25 23:33:14.396: E/SQLiteLog(32611): (1) no such table: mmsconfig
  11-25 23:33:14.403: E/Babel(32611): canonicalizeMccMnc: invalid mccmnc nullnull
  11-25 23:33:34.053: E/NetlinkEvent(298): NetlinkEvent::FindParam(): Parameter 'TIME_NS' not found
  11-25 23:33:36.619: E/WifiStateMachine(846): handleScreenStateChanged Exit: false
  11-25 23:33:36.623: E/WifiStateMachine(846): setSuspendOptimizationsNative: 4 true -want true stack:setSuspendOptimizationsNative - access$14300 - processMessage - processMsg
 11-25 23:33:36.624: E/WifiStateMachine(846): setSuspendOptimizationsNative do it 4 true stack:setSuspendOptimizationsNative - access$14300 - processMessage - processMsg
 11-25 23:33:36.624: E/native(846): do suspend true

1 个答案:

答案 0 :(得分:0)

您需要在辅助对象上调用getWritableDatabase()getReadableDatabase(),以便实际创建数据库。