2017-03-15 2 views
0

(編集:コードを動作させるための様々な試みの後に...何もありませんでした。答え:android.database.sqlite.SQLiteException:table registerd_UsersにuserTypeという名前の列がありません

private static final String KEY_ID = "id"; 
private static final String KEY_FNAME = "fullName"; 
private static final String KEY_EMAIL = "userEmail"; 
private static final String KEY_PASS = "passWord"; 
private static final String KEY_TYPE = "userType"; 

実行中、プログラムは私のUserTypeのような列がないことを私に伝えます。 両方のJavaクラスファイルのコードは次のとおりです。

DatabaseHandler.Java

package com.set.ultimax.login; 

import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 

public class DatabaseHandler extends SQLiteOpenHelper { 

// All Static variables 
// Database Version 
private static final int DATABASE_VERSION = 1; 

// Database Name 
private static final String DATABASE_NAME = "Users"; 

private static final String TABLE_USERS = "Registerd_Users"; 

// Account Table Columns names 
private static final String KEY_ID = "id"; 
private static final String KEY_FNAME = "fullName"; 
private static final String KEY_EMAIL = "userEmail"; 
private static final String KEY_PASS = "passWord"; 
private static final String KEY_TYPE = "userType"; 

public DatabaseHandler(Context context) { 
    super(context, DATABASE_NAME, null, DATABASE_VERSION); 
} 

// Creating Tables 
@Override 
public void onCreate(SQLiteDatabase db) { 
    String CREATE_ACCOUNT_TABLE = "CREATE TABLE " + TABLE_USERS + "(" 
      + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FNAME + " TEXT," + KEY_EMAIL + " TEXT," 
      + KEY_PASS + " TEXT " + KEY_TYPE + " TEXT" + ")"; 
    db.execSQL(CREATE_ACCOUNT_TABLE); 
} 

// 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); 
    onCreate(db);// Create tables again 
} 

// Adding new User 
void addUsers(Users users) { 
    SQLiteDatabase db = this.getWritableDatabase(); 

    ContentValues values = new ContentValues(); 
    values.put(KEY_FNAME, users.getFname()); //full name 
    values.put(KEY_EMAIL, users.getEmail()); // Email 
    values.put(KEY_PASS, users.getPassword()); // Password 
    values.put(KEY_TYPE, users.getuserType()); //user Type 

    // Inserting Row 
    db.insert(TABLE_USERS, null, values); 
    db.close(); // Closing database connection 
} 
public void deleteAll() //Deletes all data in the database 
{ 
    SQLiteDatabase db = this.getWritableDatabase(); 
    db.delete(TABLE_USERS,null,null); 
} 

public boolean validateUser(String fullName, String userEmail, String password, String userType){ 
    Cursor c = getReadableDatabase().rawQuery(
      "SELECT * FROM " + TABLE_USERS + " WHERE " 
        + KEY_FNAME + "='" + fullName + "'AND " 
        + KEY_EMAIL + "='" + userEmail +"'AND " 
        + KEY_PASS + "='" + password + "'AND " 
        + KEY_TYPE + "='" + userType + "'" , null); 
    if (c.getCount() > 0) { 
     return true; 
    } 
    else{return false;} 

} 
public boolean sameUser(String userEmail){ 
    Cursor c = getReadableDatabase().rawQuery(
      "SELECT * FROM " + TABLE_USERS + " WHERE " 
        + KEY_EMAIL + "='" + userEmail + "'" , null); 
    if (c.getCount() > 0) { 
     return true; 
    } 
    else{return false;} 
} 

} 

SignUp.Java

package com.set.ultimax.login; 

import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Paint; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 

public class SignUp extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.sign_up); 

    TextView goHome = (TextView) findViewById(R.id.home); 
    Button register = (Button) findViewById(R.id.reg); 

    goHome.setPaintFlags(goHome.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG); 

    goHome.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on click 
      Intent toMain = new Intent(SignUp.this, Main.class); 
      startActivity(toMain); 
     } 
    }); 

    register.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on click 
      DatabaseHandler db = new DatabaseHandler(v.getContext()); 
      Intent toMain = new Intent(SignUp.this, Main.class); 
      EditText fName = (EditText) findViewById(R.id.fName); 
      EditText email = (EditText) findViewById(R.id.Email); 
      EditText pass = (EditText) findViewById(R.id.password); 
      String fNameValue = fName.getText().toString(); 
      String emailValue = email.getText().toString(); 
      String passValue = pass.getText().toString(); 

      int charemailLength = emailValue.length(); 
      int charPassLength = passValue.length(); 
      boolean emailMatch = db.sameUser(emailValue); 

      if (emailMatch) { //Checks to see if the UserName already exists 
       Toast.makeText(SignUp.this, "UserName Already Taken", Toast.LENGTH_LONG).show(); 
      } 
      else if (emailValue.equals("") && passValue.equals("")) { 
       Toast.makeText(SignUp.this, "Fields Empty", Toast.LENGTH_SHORT).show(); 
      } 
      else if (charemailLength <= 5 && charPassLength <= 5) { 
        Toast.makeText(SignUp.this, "Characters too short", Toast.LENGTH_SHORT).show(); 
       } 
      else { 
       db.addUsers(new Users(fNameValue, emailValue, passValue,"Admin")); 
       startActivity(toMain); 
      } 

     } 

    }); 

} 
} 

私はおよそ5時間コードでプレーしてきたし、私のblinkered枯渇を通じて、私は何を見ることができません違う。どんな助けも素晴らしいだろう。

ありがとうございました!

+0

あなたのアプリをアンインストールして再インストールしてください。エラーが表示されないようにしてください。 –

+0

私はそれを行いましたが、それはうまくいきませんでしたが、回答ありがとうございます – RideTheMountainOfBlue

答えて

0
 + KEY_PASS + " TEXT " + KEY_TYPE + " TEXT" + ")"; 
          ^^ 

カンマがありません。

+0

どうでしたか?私はそれを再試行し、どのように乗っているか教えてください。途中でありがとう! – RideTheMountainOfBlue

関連する問題