0

I have made a database where name , email and password is saved.
When saving these details into the database, it is showing me error like - database doesn't have any column named email.

Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (table Users has no column named Email (code 1): , while compiling: INSERT INTO Users(Password,Email,Name) VALUES (?,?,?))

at com.example.foody.Storage.newUser(Storage.java:42)
at com.example.foody.Register$1.onClick(Register.java:32) "missing query or database"

Storage Class(helper)

package com.example.foody;

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

public class Storage extends SQLiteOpenHelper
{
    // for table 1
    public static final String d_name="Foody.db";
    public static final String t1="Users";
    public static final String c1="Name",c2="Email",c3="Password";

    public Storage(Context ct)
    {
        super(ct,d_name,null,1);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL("CREATE TABLE "+t1+"("+c1+" TEXT,"+c2+" TEXT,"+c3+" TEXT);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        db.execSQL("Drop Table If EXISTS "+t1);
        onCreate(db);
    }

    public void newUser(String a,String b,String c)
    {
        SQLiteDatabase db=this.getWritableDatabase();
        ContentValues cv=new ContentValues();
        cv.put(c1,a);
        cv.put(c2,b);
        cv.put(c3,c);
        db.insert(t1,null,cv);
        db.close();
    }

    public boolean checkUser(String email,String pass)
    {
        SQLiteDatabase db=this.getWritableDatabase();
        Cursor cr=db.rawQuery("select * from " + t1 + " where Email  = ? AND Password = ? ", new String[] {email,pass});
        if(cr.getCount()==0){
            return false;}
        else{
            return true;}
    }

}

```

Now this is the class from where I'm calling

```
package com.example.foody;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register extends AppCompatActivity
{

    Button b1;
    EditText e1,e2,e3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        e1=findViewById(R.id.sign_e1);
        e2=findViewById(R.id.sign_e2);
        e3=findViewById(R.id.sign_e3);
        b1=findViewById(R.id.sign_b1);

        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {

                Storage sob=new Storage(Register.this);
                sob.newUser(e1.getText().toString(),e2.getText().toString(),e3.getText().toString());
                Toast.makeText(Register.this,"You are registered",Toast.LENGTH_LONG).show();
                Intent it=new Intent(Register.this,Login.class);
                startActivity(it);
            }
        });
    }
}
John Joe
  • 12,412
  • 16
  • 70
  • 135

1 Answers1

0

Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database.

You need to re-install your app again since you have modified some part of your database/table(s). The version now is totally different with the previous.

John Joe
  • 12,412
  • 16
  • 70
  • 135