android contentprovider insert 时候通过contentvalues的时候失败

这个问题困扰了我一段时间,因为最近一直困扰我的小问题

1: 


public class MySqliteOpenHelper extends SQLiteOpenHelper {
    
    public static final String CREATE_TABLE_STUDENT = "CREATE TABLE " + DB_TABLE_STUDENT + " ( text "+ DB_TABLE_STUDENT_NAME + "  )";

相当于 create table student ( text name )

 

2: 我插入的时候:

ContentValues contentValues = new ContentValues();
        contentValues.put(DB_TABLE_STUDENT_NAME,"hello" + MySqliteOpenHelper.num++);
        

3: 然后在我自定义的ContentProvider 

        long insert = writableDatabase.insert(MySqliteOpenHelper.DB_TABLE_STUDENT, null, values);

4: 最后报错: 这个问题最后我发现有报错


2019-05-22 21:47:32.968 5180-5180/bjpkten.contentproviderdemo30min E/SQLiteLog: (1) table student has no column named NAME
2019-05-22 21:47:32.972 5180-5180/bjpkten.contentproviderdemo30min E/SQLiteDatabase: Error inserting NAME=hello2
    android.database.sqlite.SQLiteException: table student has no column named NAME (code 1 SQLITE_ERROR): , while compiling: INSERT INTO student(NAME) VALUES (?)
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1562)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1433)
        at bjpkten.contentproviderdemo30min.MyContentProvider.insert(MyContentProvider.java:63)
        at android.content.ContentProvider$Transport.insert(ContentProvider.java:265)
        at android.content.ContentResolver.insert(ContentResolver.java:1587)
        at bjpkten.contentproviderdemo30min.MainActivity.queryAndInsert(MainActivity.java:41)
        at java.lang.reflect.Method.invoke(Native Method)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25885)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

 

 

最后发现是sql语句的问题

应该是  create table student ( name text ) 列名在前面 name 在前面,类型在后面,尴尬?

你可能感兴趣的:(开发中遇到的问题解决,TroubleShooting,tb)