Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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
Android 未在主活动中导入MySQLiteopenhelper和数据库类_Android - Fatal编程技术网

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

Android 未在主活动中导入MySQLiteopenhelper和数据库类,android,Android,未导入sqlitedatabase类,如何在主活动中导入它 我正在开发一个使用SQlite数据库的应用程序。但是我在声明MySQLitedatabase和openhelper变量时遇到了一个错误 DatabaseHelper.java package com.example.scs.scs; import android.content.ContentValues; import android.content.Context; import android.database.Cursor;

未导入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
            }
        });

    }
}

看起来您的sqlite OpenHelper类名是
DatabaseHelper
,而不是
mysqlite OpenHelper

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