MySQLiteopenhelper和数据库类不包括在主要活动

sqlitedatabase类被导入未导入,如何导入它的主要活动MySQLiteopenhelper和数据库类不包括在主要活动

我在其中我使用的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

}

});

}

}

回答:

看起来你的源码开放的助手类的名字是DatabaseHelper而不是MySQliteOpenHelper

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

以上是 MySQLiteopenhelper和数据库类不包括在主要活动 的全部内容, 来源链接: utcz.com/qa/265438.html

回到顶部