MySQLiteopenhelper和数据库类未在主活动中导入

时间:2017-12-27 13:43:13

标签: android

未导入sqlitedatabase类,如何在主活动中导入

我正在开发一个使用SQlite数据库的应用程序。但我在MySQLitedatabase和openhelper变量的变量声明中面临错误。

DatabaseHelper.java

package com.example.scs.scs;

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


public class DatabaseHelper extends SQLiteOpenHelper{
    private static final int DATABASE_VERSION=1;
    private static final String DATABASE_NAME="UserRegistration";
    private  String TABLE_REGDETAIL="UserRegistration";
    private  String KEY_ID="id";
    private  String KEY_FIRSTNAME="firstname";
    private  String KEY_LASTNAME="lastname";
    private  String KEY_EMAIL="email";
    private  String KEY_PASSWORD="password";
    private  String KEY_HINT="hint";
    private  String KEY_COUNTRY="country";
    private  String KEY_CONTACTNO="contactno";
    public DatabaseHelper(Context context)
    {
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
String CREATE_REGDETAIL_TABLE="CREATE TABLE"+TABLE_REGDETAIL+"("
        +KEY_ID+"INTEGER,"+KEY_FIRSTNAME+"TEXT,"+KEY_LASTNAME+"TEXT,"+KEY_EMAIL+"TEXT PRIMARY KEY,"+KEY_PASSWORD+"TEXT,"+KEY_HINT+"TEXT,"+KEY_COUNTRY+"TEXT,"
    +KEY_CONTACTNO+"TEXT"+")";
    db.execSQL(CREATE_REGDETAIL_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS"+TABLE_REGDETAIL);
        onCreate(db);

    }}




MainActivity.java


package com.example.scs.scs;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Registration extends AppCompatActivity {
  MySQliteOpenHelper mySqliteOpenHelper;
    private MySQLiteDatabase database;
    TextView fname, lname, remail, r_pass, contctnum, r_hint, r_country; //declaring variables for editview
    Button btnreg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);
        DatabaseHelper db = new DatabaseHelper(this);
        fname = (TextView) findViewById(R.id.edtfrstname);
        lname = (TextView) findViewById(R.id.edtlastname);
        remail = (TextView) findViewById(R.id.edtreg_email);
        r_pass = (TextView) findViewById(R.id.edtreg_pass);
        contctnum = (TextView) findViewById(R.id.edtcontactnum);
        r_hint = (TextView) findViewById(R.id.edtpass_hint);
        r_country = (TextView) findViewById(R.id.edtcountry);
        btnreg = (Button) findViewById(R.id.btnregister);
        Typeface myCustomFont = Typeface.createFromAsset(getAssets(), "fonts/Gabriola.ttf");
        fname.setTypeface(myCustomFont);//font style of frst name edittext
        lname.setTypeface(myCustomFont);//font style of last name edittext
        remail.setTypeface(myCustomFont);//font style of reg email button
        r_pass.setTypeface(myCustomFont);//font style of reg pass button
        contctnum.setTypeface(myCustomFont);//font style of  contact num
        r_hint.setTypeface(myCustomFont);//font style of reg hint
        r_country.setTypeface(myCustomFont);//font style of reg country
        btnreg.setTypeface(myCustomFont);

        btnreg = (Button) findViewById(R.id.btnregister);
        btnreg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mySqliteOpenHelper = new MySQLiteOpenHelper(getApplicationContext());



            }
        });

    }
}

MainActivity.java

package com.example.scs.scs;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Registration extends AppCompatActivity {
  MySQliteOpenHelper mySqliteOpenHelper;
    private MySQLiteDatabase database;
    TextView fname, lname, remail, r_pass, contctnum, r_hint, r_country; //declaring variables for editview
    Button btnreg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);
        DatabaseHelper db = new DatabaseHelper(this);
        fname = (TextView) findViewById(R.id.edtfrstname);
        lname = (TextView) findViewById(R.id.edtlastname);
        remail = (TextView) findViewById(R.id.edtreg_email);
        r_pass = (TextView) findViewById(R.id.edtreg_pass);
        contctnum = (TextView) findViewById(R.id.edtcontactnum);
        r_hint = (TextView) findViewById(R.id.edtpass_hint);
        r_country = (TextView) findViewById(R.id.edtcountry);
        btnreg = (Button) findViewById(R.id.btnregister);
        Typeface myCustomFont = Typeface.createFromAsset(getAssets(), "fonts/Gabriola.ttf");
        fname.setTypeface(myCustomFont);//font style of frst name edittext
        lname.setTypeface(myCustomFont);//font style of last name edittext
        remail.setTypeface(myCustomFont);//font style of reg email button
        r_pass.setTypeface(myCustomFont);//font style of reg pass button
        contctnum.setTypeface(myCustomFont);//font style of  contact num
        r_hint.setTypeface(myCustomFont);//font style of reg hint
        r_country.setTypeface(myCustomFont);//font style of reg country
        btnreg.setTypeface(myCustomFont);

        btnreg = (Button) findViewById(R.id.btnregister);
        btnreg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mySqliteOpenHelper = new MySQLiteOpenHelper(getApplicationContext());
                database = mySqliteOpenHelper.getReadable
            }
        });

    }
}

1 个答案:

答案 0 :(得分:0)

您的sqlite打开帮助程序类名称似乎是DatabaseHelper而不是MySQliteOpenHelper

MySQLiteDatabase可以替换为SQLiteDatabase,因为您很少需要专门化它。