我的错误
https://i.stack.imgur.com/sWcfc.png
08-01 10:30:37.922 10238-10238 / com.example.androiddev.army31 E / SQLiteLog:(1)表用户没有名为email的列
08-01 10:30:37.923 10238-10238 / com.example.androiddev.army31 E / SQLiteDatabase:插入手机= 4321名称= 4321姓氏= 4321电子邮件= 597ff5de5808e6.61338449 created_at = 4321 uid = 4321 id_card = 2017-08错误-01 10:30:38 users_name = 4321
android.database.sqlite.SQLiteException: table user has no column named email (code 1): , while compiling: INSERT INTO user(mobile,name,lastname,email,created_at,uid,id_card,users_name) VALUES (?,?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1472)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
at com.example.androiddev.army31.helper.SQLiteHandler.addUser(SQLiteHandler.java:89)
at com.example.androiddev.army31.LoginScreen.Sign_up$2.onResponse(Sign_up.java:152)
at com.example.androiddev.army31.LoginScreen.Sign_up$2.onResponse(Sign_up.java:126)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
我的SQLite代码我找不到这个问题
我试图多次更改任何值并得到相同的错误
public SQLiteHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USERS + "("
+ KEY_USERS_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_LASTNAME + " TEXT ,"
+ KEY_ID_CARD + " TEXT ," + KEY_MOBILE + " TEXT ,"
+ KEY_USERS_NAME + " TEXT UNIQUE," + KEY_UID + " TEXT," + KEY_EMAIL + "TEXT "
+ KEY_CREATED_AT + " TEXT" + ")";
db.execSQL(CREATE_LOGIN_TABLE);
Log.d(TAG, "Database tables created");
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
// Create tables again
onCreate(db);
}
/**
* Storing user details in database
* */
public void addUser(String name, String lastname , String users_name
,String email , String id_card , String mobile , String uid, String created_at) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, name); // Name
values.put(KEY_LASTNAME , lastname); //LastName
values.put(KEY_USERS_NAME, users_name);
values.put(KEY_EMAIL , email);
values.put(KEY_ID_CARD , id_card);
values.put(KEY_MOBILE , mobile);
values.put(KEY_UID, uid); // Email
values.put(KEY_CREATED_AT, created_at); // Created At
// Inserting Row
long id = db.insert(TABLE_USERS, null, values);
db.close(); // Closing database connection
Log.d(TAG, "New user inserted into sqlite: " + id);
}
/**
* Getting user data from database
* */
public HashMap<String, String> getUserDetails() {
HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "SELECT * FROM " + TABLE_USERS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if (cursor.getCount() > 0) {
user.put("name", cursor.getString(1));
user.put("lastname" , cursor.getString(2));
user.put("users_name", cursor.getString(3));
user.put("email" , cursor.getString(4));
user.put("id_card" , cursor.getString(5));
user.put("mobile" , cursor.getString(6));
user.put("uid", cursor.getString(7));
user.put("created_at", cursor.getString(8));
}
cursor.close();
db.close();
// return user
Log.d(TAG, "Fetching user from Sqlite: " + user.toString());
return user;
}
这里从我的主要代码来实现SQLite从注册表中存储
并检查登录屏幕
// Session manager
session = new SessionManager(getApplicationContext());
// SQLite database handler
db = new SQLiteHandler(getApplicationContext());
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(Sign_up.this,
ReportActivity.class);
startActivity(intent);
finish();
}
// Progress dialog
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
mContext = this;
// Register Button Click event
btnSignUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String name = etFname.getText().toString().trim();
String lastname = etLname.getText().toString().trim();
String users_name = etUser.getText().toString().trim();
String password = etPassword.getText().toString().trim();
String id_card = etIdCard.getText().toString().trim();
String mobile = etMobile.getText().toString().trim();
String email = etEmail.getText().toString().trim();
if (!name.isEmpty() && !lastname.isEmpty() && !users_name.isEmpty() && !password.isEmpty() &&!email.isEmpty()
&&!id_card.isEmpty() &&!mobile.isEmpty() ) {
registerUser(name, lastname , users_name, email, id_card , password , mobile);
} else {
Toast.makeText(getApplicationContext(),
"Please enter your details!", Toast.LENGTH_LONG)
.show();
}
}
});
}
private void registerUser(final String name, final String lastname ,final String users_name,
final String email , final String id_card ,final String mobile ,final String password) {
// Tag used to cancel the request
String tag_string_req = "req_register";
progressDialog.setMessage("Registering ...");
showDialog();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
// User successfully stored in MySQL
// Now store the user in sqlite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String lastname = user.getString("lastname");
String users_name = user.getString("users_name");
String created_at = user
.getString("created_at");
String email = user.getString("email");
String id_card = user.getString("id_card");
String mobile = user.getString("mobile");
db.addUser(name, lastname , users_name, uid, created_at , email , id_card ,mobile);
最佳答案
您收到错误“表用户没有名为email的列”,这意味着列创建中存在问题。
因此,请确保执行以下步骤:
更改您的创建查询,例如@Avi Answer
喜欢
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USERS + "("
+ KEY_USERS_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_LASTNAME + " TEXT ,"
+ KEY_ID_CARD + " TEXT ," + KEY_MOBILE + " TEXT ,"
+ KEY_USERS_NAME + " TEXT UNIQUE," + KEY_UID + " TEXT," + KEY_EMAIL + "TEXT "
+ KEY_CREATED_AT + " TEXT" + ")";
db.execSQL(CREATE_LOGIN_TABLE);
Log.d(TAG, "Database tables created");
}
这里您在文本数据类型之前缺少一个逗号和一个空格(在
KEY_EMAIL)
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USERS + "("
+ KEY_USERS_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_LASTNAME + " TEXT ,"
+ KEY_ID_CARD + " TEXT ," + KEY_MOBILE + " TEXT ,"
+ KEY_USERS_NAME + " TEXT UNIQUE," + KEY_UID + " TEXT," + KEY_EMAIL + " TEXT ,"
+ KEY_CREATED_AT + " TEXT" + ")";
更改此查询后,请卸载应用并重新安装。
希望对您有帮助。
谢谢