Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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 SQLite给我一个靠近“的错误”;创建";:语法错误(代码1)_Android_Sqlite_Android Sqlite - Fatal编程技术网

Android SQLite给我一个靠近“的错误”;创建";:语法错误(代码1)

Android SQLite给我一个靠近“的错误”;创建";:语法错误(代码1),android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,我创建DbManger类来处理Sqlite数据库操作,我尝试在数据库中插入值,但它给出了一个错误 E/SQLiteDatabase(6729):android.database.sqlite.SQLiteException:靠近“CREATE”:语法错误(代码1),编译时:插入到CREATE表关系中(_idinteger主键自动递增,名称文本不为NULL,电子邮件文本不为NULL,年龄文本不为NULL,位置文本不为NULL);(电子邮件、姓名、年龄、位置)值(?、、?、?) 数据库管理器类 pu

我创建DbManger类来处理Sqlite数据库操作,我尝试在数据库中插入值,但它给出了一个错误

E/SQLiteDatabase(6729):android.database.sqlite.SQLiteException:靠近“CREATE”:语法错误(代码1),编译时:插入到CREATE表关系中(_idinteger主键自动递增,名称文本不为NULL,电子邮件文本不为NULL,年龄文本不为NULL,位置文本不为NULL);(电子邮件、姓名、年龄、位置)值(?、、?、?)

数据库管理器类

public class DBManager {

    int rowsAffected;

    // Database and version
    private static final String DB_NAME = "familyHistory";
    private static final int DB_VERSION = 1;

    private static final String TABLE_INFO = "familyTable"; 

    private static final String _ROWID = "_id";
    private static final String _NAME = "name";
    private static final String _EMAIL = "email";
    private static final String _AGE = "age";
    private static final String _LOCATIONs = "location"; 

    private static final String CREATE_PRO = "CREATE TABLE " + TABLE_INFO + "(" + 
            _ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
            _NAME + " TEXT NOT NULL, " + 
            _EMAIL + " TEXT NOT NULL, " + 
            _AGE + " TEXT NOT NULL, " + 
            _LOCATIONs + " TEXT NOT NULL);";

    private final Context ourContext;
    private static DBHelper ourDBHelper;
    private SQLiteDatabase ourDatabase;

    public DBManager(Context ctx) {
        this.ourContext = ctx;
        Log.i("db", "DBManager(Context ctx)");
    }

    private static class DBHelper extends SQLiteOpenHelper {

        public DBHelper(Context context) {
            // SQLiteOpenHelper Constructor Creating database
            super(context, DB_NAME, null, DB_VERSION);
            Log.i("db", "DBHelper(Context context)");
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(CREATE_PRO);
            Log.e(">>>>>", CREATE_PRO);
            // db.execSQL(CREATE_TRVLBOK);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) {
            Log.w("Nomad", "Upgrading database from version " + oldVer + " to " + newVer
                    + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_INFO);
            // db.execSQL("DROP TABLE IF EXISTS " + TABLE_TRAVELBOK);
            onCreate(db);
            Log.i("db", "onUpgrade)");
        }

    }

    public DBManager open() throws SQLException {
        ourDBHelper = new DBHelper(ourContext);
        ourDatabase = ourDBHelper.getWritableDatabase();
        Log.i("db", "open()");
        return this;
    }

    public void close() {
        ourDBHelper.close();
        Log.i("db", "close()");
    }



    public long insertFamRec(String UserName, String Email, String age, String location) {
        ContentValues cv = new ContentValues();
        cv.put(_NAME, UserName);
        cv.put(_EMAIL, Email);
        cv.put(_AGE, age);
        cv.put(_LOCATIONs, location);
        Log.i("db", "insertLocRec");
        return ourDatabase.insert(CREATE_PRO, null, cv);

    }
}
从插入类中,我添加了这些行,但仍然有错误

DBManager db = new DBManager(NewRelation.this);
    db.open(); 
    long i = db.insertFamRec("strfullName", "stremail", "strage", "strlocation");

    db.close();
    if (i > 0) {
         ShowMessage.Message(NewRelation.this, "data is added");
    } else {
        Toast.makeText(getApplicationContext(), "data is failed", Toast.LENGTH_SHORT).show();
    }

如果有人给出了问题的评分,请说明原因。

问题似乎出现在您调用数据库的地方。插入时,您将在表名的位置传递查询字符串。您希望通过这一行实现什么:
returnourdatabase.insert(CREATE_PRO,null,cv)

将行更改为:

return ourDatabase.insert(TABLE_INFO, null, cv);
注意,我传递的不是
CREATE_PRO
,而是要插入的表的名称
TABLE_INFO

我希望这能解决你的问题。如果有帮助,请告诉我。

问题似乎出在您调用我们的数据库的地方。如果插入
,您将在表名的位置传递查询字符串。您希望通过这一行实现什么:
returnourdatabase.insert(CREATE_PRO,null,cv)

将行更改为:

return ourDatabase.insert(TABLE_INFO, null, cv);
注意,我传递的不是
CREATE_PRO
,而是要插入的表的名称
TABLE_INFO

我希望这能解决你的问题。如果有帮助,请告诉我。

谢谢@ishmael我忘了!复制粘贴的缺点:P:)复制和粘贴可能会很昂贵!我很高兴我能提供帮助,如果你觉得答案有用,请投票。谢谢@ishmael我忘了!复制粘贴的缺点:P:)复制和粘贴可能会很昂贵!我很高兴能够提供帮助,如果你觉得答案有用,请投票表决。