Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Java 创建android注册页面时出现数据库连接问题?_Java_Android - Fatal编程技术网

Java 创建android注册页面时出现数据库连接问题?

Java 创建android注册页面时出现数据库连接问题?,java,android,Java,Android,请帮我输入这段代码。数据库已成功创建,表也已成功创建,但记录未进入表中。它显示成功注册,但不显示表中的任何记录。下面我附上了不同等级的代码 注册地址:i.java public class RegistrationAlumini extends AppCompatActivity { EditText first, last, email, mobile, currentjob, currentcity, currentcomp, dob,poy,feedback; Button

请帮我输入这段代码。数据库已成功创建,表也已成功创建,但记录未进入表中。它显示成功注册,但不显示表中的任何记录。下面我附上了不同等级的代码

注册地址:i.java

public class RegistrationAlumini extends AppCompatActivity {
    EditText first, last, email, mobile, currentjob, currentcity, currentcomp, dob,poy,feedback;
    Button save, cancel;
    DatabaseHandler db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration_alumini);

        first = (EditText) findViewById(R.id.editfirstname);
        last = (EditText) findViewById(R.id.editlastname);
        email = (EditText) findViewById(R.id.editemail);
        mobile = (EditText) findViewById(R.id.editmobileno);
        currentjob = (EditText) findViewById(R.id.editcurrentjob);
        currentcity = (EditText) findViewById(R.id.editcurrentcity);
        currentcomp = (EditText) findViewById(R.id.editcurrentcompany);
        dob = (EditText) findViewById(R.id.editdob);
        poy = (EditText) findViewById(R.id.editpoy);
        feedback = (EditText) findViewById(R.id.editfb);

        save = (Button) findViewById(R.id.btnsave);
        cancel = (Button) findViewById(R.id.btncancel);

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String edfirst = first.getText().toString();
                String edlast = last.getText().toString();
                String edemail = email.getText().toString();
                String edmobile = mobile.getText().toString();
                String edcurrentjob = currentjob.getText().toString();
                String edcurrentcity = currentcity.getText().toString();
                String edcurrentcomp = currentcomp.getText().toString();
                String eddob = dob.getText().toString();
                String edpoy = poy.getText().toString();
                String edfeedback = feedback.getText().toString();

                if(first.getText().toString().length()==0 ){
                    first.setError("First name not entered");
                    first.requestFocus();
                }
                if(last.getText().toString().length()==0){
                    last.setError("Last name not entered");
                    last.requestFocus();
                }

                if(email.getText().toString().length()==0){
                    email.setError("Email is required");
                    email.requestFocus();
                }
                if(mobile.getText().toString().length()<10 ){
                    mobile.setError("Mobile number shall be 10 digit");
                    mobile.requestFocus();
                }
                if(currentjob.getText().toString().length()==0){
                    currentjob.setError("Current job is required");
                    currentjob.requestFocus();
                }
                if(currentcity.getText().toString().length()==0){
                    currentcity.setError("Current city is required");
                    currentcity.requestFocus();
                }
                if(currentcomp.getText().toString().length()==0){
                    currentcomp.setError("current company or organization is required");
                    currentcomp.requestFocus();
                }

                if(dob.getText().toString().length()==0){
                    dob.setError("date of birth is required");
                    dob.requestFocus();
                }
                if(poy.getText().toString().length()==0 ){
                    poy.setError("pass out year is required ");
                    poy.requestFocus();
                }
                if(feedback.getText().toString().length()==0){
                    feedback.setError("Feedback is required");
                    feedback.requestFocus();
                }

                db = new DatabaseHandler(RegistrationAlumini.this, null, null, 2);
                Registerdata reg = new Registerdata();

                reg.setfirstName(edfirst);
                reg.setlastName(edlast);
                reg.setEmailId(edemail);
                reg.setmobileno(edmobile);
                reg.setcurrentjob(edcurrentjob);
                reg.setcurrentcity(edcurrentcity);
                reg.setcurrentcomp(edcurrentcomp);
                reg.setdob(eddob);
                reg.setpoy(edpoy);
                reg.setfeedback(edfeedback);
                db.addregister(reg);
                Toast.makeText(getApplicationContext(), "Registered", Toast.LENGTH_LONG).show();
                startActivity(new Intent(getApplicationContext(),RegistrationAlumini.class));
            }

        });

    }

RegisterData.java

public class Registerdata {

    int _id;
    String first_name;
    String last_name;
    String email_id;
    String mobile_number;
    String current_job;
    String current_city;
    String current_comp;
    String d_o_b;
    String p_o_y;
    String feed_back;

    public Registerdata(){

    }

    public Registerdata(int id, String first_name, String  last_name,String email_id,String mobile_number, String current_job,
                        String current_city, String current_comp, String d_o_b, String p_o_y, String feed_back){
        this._id = id;
        this.first_name = first_name;
        this.last_name = last_name;
        this.email_id=email_id;
        this.mobile_number=mobile_number;
        this.current_job = current_job;
        this.current_city = current_city;
        this.current_comp = current_comp;
        this.d_o_b = d_o_b;
        this.p_o_y = p_o_y;
        this.feed_back = feed_back;
    }
    public  int getID(){ return this._id; }

    // setting id
    public void setID(int id){
        this._id = id;
    }
    public String getFirst_name() {
        // TODO Auto-generated method stub
        return first_name;
    }
    // setting  first name
    public void setfirstName(String first_name){
        this.first_name = first_name;
    }
    public String getLast_name(){
        return last_name;
    }
    public void setlastName(String last_name){
        this.last_name = last_name;
    }
    public String getEmail_id(){
        return email_id;
    }
    public void setEmailId(String email_id){
        this.email_id = email_id;
    }
    public String getMobile_number(){
        return mobile_number;
    }
    public void setmobileno(String mobile_number){
        this.mobile_number = mobile_number;
    }
    public String getCurrent_job(){
        return current_job;
    }
    public void setcurrentjob(String current_job){
        this.current_job = current_job;
    }
    public String getCurrent_city(){
        return current_city;
    }
    public void setcurrentcity(String current_city){
        this.current_city = current_city;
    }
    public String getCurrent_comp(){
        return current_comp;
    }
    public void setcurrentcomp(String current_comp){
        this.current_comp = current_comp;
    }
    public String getD_o_b(){
        return d_o_b;
    }
    public void setdob(String d_o_b){
        this.d_o_b = d_o_b;
    }
    public String getP_o_y(){
        return p_o_y;
    }
    public void setpoy(String p_o_y){
        this.p_o_y = p_o_y;
    }
    public String getFeed_back(){
        return feed_back;
    }
    public void setfeedback(String feed_back){
        this.feed_back = feed_back;
    }
}

here is log 

2020-10-08 20:30:43.326 13701-13701/com.lcit.lcitnewdemo E/SQLiteLog: (1) table register has no column named feed_back in "INSERT INTO register( first_name,feed_back,id,mobile_number,d_o_b,p_o_y,current_job,email_id,current_city,current_comp,last_name) VALUES (?,?,?,?,?,?,?,?,?,?,?)
2020-10-08 20:30:43.328 13701-13701/com.lcit.lcitnewdemo E/SQLiteDatabase: Error inserting  first_name=dfdsfdf feed_back=vcxvxcv id=0 mobile_number=1232322344 d_o_b=12-09-1986 p_o_y=2009 current_job=xvcvcv email_id=zczc@ghgh.com current_city=xcvxvx current_comp=xcvxcv last_name=xxcvxv
    android.database.sqlite.SQLiteException: table register has no column named feed_back (code 1 SQLITE_ERROR): , while compiling: INSERT INTO register( first_name,feed_back,id,mobile_number,d_o_b,p_o_y,current_job,email_id,current_city,current_comp,last_name) VALUES (?,?,?,?,?,?,?,?,?,?,?)
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:652)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:33)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1699)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1570)
        at com.lcit.lcitnewdemo.DatabaseHandler.addregister(DatabaseHandler.java:74)
        at com.lcit.lcitnewdemo.RegistrationAlumini$1.onClick(RegistrationAlumini.java:108)
        at android.view.View.performClick(View.java:7438)
        at android.view.View.performClickInternal(View.java:7415)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28286)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
2020-10-08 20:30:43.329 13701-13701/com.lcit.lcitnewdemo D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10163; state: ENABLED
公共类注册数据{
内部id;
字符串名;
字符串last_name;
字符串电子邮件地址;
字符串移动电话号码;
字符串当前工作;
串当前城市;
串电流补偿;
字符串d_o_b;
字符串p_____y;
串反馈;
公共注册数据(){
}
公共注册数据(int-id、String-first\u-name、String-last\u-name、String-email\u-id、String-mobile\u-number、String-current\u-job、,
字符串当前\u城市、字符串当前\u comp、字符串d\u o\u b、字符串p\u o\u y、字符串反馈){
这个。_id=id;
this.first\u name=first\u name;
this.last_name=last_name;
this.email\u id=email\u id;
这个.mobile\u number=mobile\u number;
this.current_job=当前_job;
this.current_city=当前_city;
this.current_comp=current_comp;
this.d_o_b=d_o_b;
this.p_o_y=p_o_y;
this.feed\u back=反馈;
}
public int getID(){返回此。\u id;}
//设置id
公共无效集合id(内部id){
这个。_id=id;
}
公共字符串getFirst_name(){
//TODO自动生成的方法存根
返回第一个名称;
}
//设置名字
public void setfirstName(字符串first_name){
this.first\u name=first\u name;
}
公共字符串getLast_name(){
返回姓氏;
}
public void setlastName(字符串last_name){
this.last_name=last_name;
}
公共字符串getEmail_id(){
返回电子邮件地址;
}
public void setEmailId(字符串email\u id){
this.email\u id=电子邮件\u id;
}
公共字符串getMobile_number(){
返回手机号码;
}
公共无效setmobileno(字符串移动号码){
this.mobile\u number=mobile\u number;
}
公共字符串getCurrent_作业(){
返回当前作业;
}
public void setcurrentjob(字符串current_job){
this.current_job=当前_job;
}
公共字符串getCurrent_city(){
返回当前城市;
}
公共无效设置当前城市(字符串当前城市){
this.current_city=当前_city;
}
公共字符串getCurrent_comp(){
返回电流_comp;
}
公共void setcurrentcomp(字符串current\u comp){
this.current_comp=current_comp;
}
公共字符串getD_o_b(){
返回d_o_b;
}
公共void setdob(字符串d_o_b){
this.d_o_b=d_o_b;
}
公共字符串getP_o_y(){
返回p______y;
}
公共无效设置(字符串p_o__y){
this.p_o_y=p_o_y;
}
公共字符串getFeed_back(){
返回反馈;
}
公共无效设置反馈(字符串反馈){
this.feed\u back=反馈;
}
}
这是日志
2020-10-08 20:30:43.326 13701-13701/com.lcit.lcitnewdemo E/SQLiteLog:(1)表格寄存器在“插入到寄存器(名字、反馈、id、手机号、d__b、p_y、当前工作、电子邮件id、当前城市、当前公司、姓氏)值(?,,,,,,,,,,,,?,,,,,,,?)
2020-10-08 20:30:43.328 13701-13701/com.lcit.lcitnewdemo E/SQLiteDatabase:插入first_name=dfdsfdf feed_back=vcxvxcv id=0 mobile_number=1232322344 d_o_b=12-09-1986 p_o_y=2009当前工作=xvcvcv email_id=zczc@ghgh.com当前城市=XCVxV当前公司=XCVxV姓氏=xxcvxv
android.database.sqlite.SQLiteException:表寄存器没有名为feed_back的列(代码1 sqlite_错误):,编译时:插入寄存器(名字、反馈、id、手机号、d_o_b、p_o_y、当前_作业、电子邮件id、当前_城市、当前_comp、姓氏)值(?,,,,,,,?,,,,?)
位于android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法)
位于android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)
位于android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:652)
位于android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
位于android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:61)
位于android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:33)
位于android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1699)
位于android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1570)
位于com.lcit.lcitnewdemo.DatabaseHandler.addregister(DatabaseHandler.java:74)
在com.lcit.lcitnewdemo.RegistrationAlumini$1.onClick上(RegistrationAlumini.java:108)
在android.view.view.performClick上(view.java:7438)
在android.view.view.performClickInternal(view.java:7415)
在android.view.view.access$3600(view.java:810)
在android.view.view$PerformClick.run(view.java:28286)
位于android.os.Handler.handleCallback(Handler.java:938)
位于android.os.Handler.dispatchMessage(Handler.java:99)
位于android.os.Looper.loop(Looper.java:223)
位于android.app.ActivityThread.main(ActivityThread.java:7523)
位于java.lang.reflect.Method.invoke(本机方法)
位于com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
2020-10-08 20:30:43.329 13701-13701/com.lcit.lcitnewdemo D/CompatibilityChangeReporter:报告的兼容更改id:147798919;UID 10163;状态:已启用

创建表
中定义表时,您忘记在
的“TEXT”
中添加一些空格。当它试图创建表时,您应该得到一个异常。我在这里更正了它:

public static final String CREATE_TABLE="CREATE TABLE " + TABLE_REGISTER + "("
        + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FIRST_NAME + " TEXT,"+KEY_lAST_NAME + " TEXT,"+KEY_EMAIL_ID+ " TEXT,"
        + KEY_MOB_NO + " TEXT," + KEY_CURRENT_JOB+ " TEXT ," + KEY_CURRENT_CITY+" TEXT,"+KEY_CURRENT_COMP+" TEXT,"+
        KEY_DATE_OF_BIRTH+" TEXT,"+ KEY_PASS_OUT_YEAR+" TEXT,"+KEY_FEED_BACK+" TEXT"+")";
public static final String CREATE_TABLE="CREATE TABLE " + TABLE_REGISTER + "("
        + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FIRST_NAME + " TEXT,"+KEY_lAST_NAME + " TEXT,"+KEY_EMAIL_ID+ " TEXT,"
        + KEY_MOB_NO + " TEXT," + KEY_CURRENT_JOB+ " TEXT ," + KEY_CURRENT_CITY+" TEXT,"+KEY_CURRENT_COMP+" TEXT,"+
        KEY_DATE_OF_BIRTH+" TEXT,"+ KEY_PASS_OUT_YEAR+" TEXT,"+KEY_FEED_BACK+" TEXT"+")";