Good evening to all, I am creating an application with java on android studio.but after creating my database and making the registration page, the information does not go into the database.the errors I had said that there is a colons not created, I checked and everything is in place. when I remove the code that allows the insertion of information in the database the application works if not it is blocked at the stage of registration.I also tried nothing
A part of my database code
public static final String DATABASE_NAME = "Login.db";
public static final String TABLE_SIGN = "userss";
//public static final String TABLE_PROSPECT = "prospect";
public static final int DATABASE_VERSION = 1;
public static final String ID_COL= "id";
public static final String NAME_COL = "name";
public static final String USERNAME_COL = "username";
public static final String EMAIL_COL = "email";
public static final String PHONE_COL = "phone";
public static final String PASSWORD_COL = "password";
public MyDbHandler(Context context) {
super(context,DATABASE_NAME,null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE "+ TABLE_SIGN
+ "(" + ID_COL + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,"+
NAME_COL + "TEXT,"+ USERNAME_COL + "TEXT," + EMAIL_COL + "TEXT," + PHONE_COL
+ " TEXT,"+ PASSWORD_COL + "TEXT);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SIGN);
}
public boolean insertData(String name, String username, String email, String phone, String password)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(NAME_COL, name);
contentValues.put(USERNAME_COL,username);
contentValues.put(EMAIL_COL,email);
contentValues.put(PHONE_COL,phone);
contentValues.put(PASSWORD_COL,password);
long result = db.insert(TABLE_SIGN, null,contentValues);
if(result == -1)
{
return false;
}else
{
return true;
}
}
The registration methods
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nam = name.getText().toString();
String user = username.getText().toString();
String email = mail.getText().toString();
String phoneN = phoneNo.getText().toString();
String pass = password.getText().toString();
if(nam.equals("") && user.equals("") && email.equals("") && phoneN.equals("") && pass.equals(""))
{
Toast.makeText(SignUp.this,"Veuillez remplir tout les champs",Toast.LENGTH_SHORT).show();
}
else{
Boolean regResult = db.insertData(nam,user,email,phoneN,pass);
if(regResult == true)
{
Toast.makeText(SignUp.this,"Connexion réussie avec succès",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),LogIn.class);
startActivity(intent);
}
else
{
Toast.makeText(SignUp.this,"Echec de connexion",Toast.LENGTH_SHORT).show();
}
}
}
});
The errors that i have:
2021-06-23 22:51:16.489 28861-28861/com.example.suiviprospection E/SQLiteLog: (1) table userss has no column named email
2021-06-23 22:51:16.490 28861-28861/com.example.suiviprospection E/SQLiteDatabase: Error inserting phone=60005882 email=shiv@gmail.com name=GOGNON Shiva password=Shiv username=shiv
android.database.sqlite.SQLiteException: table userss has no column named email (code 1): , while compiling: INSERT INTO userss(phone,email,name,password,username) 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.suiviprospection.MyDbHandler.insertData(MyDbHandler.java:76)
at com.example.suiviprospection.SignUp$1.onClick(SignUp.java:48)
at android.view.View.performClick(View.java:5637)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:22429)
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:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Thank you for helping me , I'm waiting for your answers