因此,我在android studio中编写登录和注册代码,让我粘贴到这里:
package com.example.myapplication.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.widget.*;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class database extends SQLiteOpenHelper {
private final static String dbName = "user.db";
private final static String tableName = "customer";
private int Id;
private static final String ID_COL = "ID";
private static final String NAME_COL = "NAME";
private static final String EMAIL_COL = "EMAIL";
private static final String PASS_COL = "PASS";
private static final String MOBILE_COL = "MOBILE";
private final static int dbVersion = 3;
Context context;
public database(Context context){
super(context,dbName,null,dbVersion);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase = this.getWritableDatabase();
String query = "CREATE TABLE IF NOT EXISTS " + tableName + "(" + ID_COL + " VARCHAR(50) PRIMARY KEY," + NAME_COL + " VARCHAR(50)," + EMAIL_COL + " VARCHAR(50)," + PASS_COL + " VARCHAR(50), "+MOBILE_COL+" VARCHAR(50));";
sqLiteDatabase.execSQL(query);
}
public boolean checkAlreadyExists(){
SQLiteDatabase db = this.getReadableDatabase();
String check = "SELECT * FROM "+tableName+" WHERE ID ="+Id+";";
Cursor cursor = db.rawQuery(check,null);
if(cursor.getCount() > 0){
cursor.close();
return true;
}
else
{
cursor.close();
return false;
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS "+tableName);
onCreate(db);
}
public void addRecord(String id,String name,String email,String pass){
SQLiteDatabase sql = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(ID_COL,id);
values.put(NAME_COL,name);
values.put(EMAIL_COL,email);
values.put(PASS_COL,pass);
if(!checkAlreadyExists()) {
long res = sql.insert(tableName,null,values);
if(res==-1) {
Toast.makeText(context, "Registration Failed", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(context,"You Have Been Registered..//",Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(context,"User Already Exists.Please Login.",Toast.LENGTH_LONG).show();
}
}
public boolean login(String loginId,String loginPass){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(tableName,null,ID_COL+" = ? AND "+PASS_COL+" =? ",new String[]{loginId,loginPass},null,null,null);
try
{
if(cursor.moveToFirst())
return true;
}catch(Exception e){
String message = e.getMessage();
Log.v("Database.java","login:"+e.getMessage());
}
finally {
cursor.close();
}
return false;
}
}
这是按钮按下的代码:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.myapplication.database.database;
public class RegisterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initializeUI();
}
private String id;
private int Id;
private String name;
private String pass;
private String email;
private String confirm;
private String mobile;
private EditText NAME;
private EditText PASSWORD;
private EditText CONFIRMPASSWORD;
private EditText EMAIL;
private EditText REGISTER;
private EditText ID;
//Below method initializes the UI.
public void initializeUI(){
ID = (EditText)findViewById(R.id.registerID);
NAME = (EditText) findViewById(R.id.registerName);
PASSWORD = (EditText) findViewById(R.id.registerPassword);
EMAIL = (EditText) findViewById(R.id.registerEmail);
CONFIRMPASSWORD = (EditText) findViewById(R.id.registerConfirmPassword);
}
//Register process gets called.
public void buttonPressed(View view){
database db = new database(RegisterActivity.this);
id = ID.getText().toString();
name = NAME.getText().toString();
email = EMAIL.getText().toString();
pass = PASSWORD.getText().toString();
confirm = CONFIRMPASSWORD.getText().toString();
//Seeing if the password matches.
if (pass.equals(confirm)) {
db.addRecord(id, name, email, pass);
ID.setText("");
NAME.setText("");
EMAIL.setText("");
PASSWORD.setText("");
CONFIRMPASSWORD.setText("");
Intent in = new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(in);
} else {
Toast.makeText(RegisterActivity.this, "Password are Incorrect..//", Toast.LENGTH_LONG).show();
}
}
}
我得到以下异常:
E/androidRuntime:致命异常:主进程:com.example.myapplication,PID:3980 Java . lang . illegalstateexception:无法执行Android的方法:onClick at Android x . app compat . app . appcompatviewinflater$declaredonclicklistener . onClick(appcompatviewinflater . Java:446)at Android . view . view . perform click(view . Java:5610)at com . Google . Android . material . button . material button . perform click(material button . Java:1133
您应该始终查找异常的原因
部分:
Caused by: java.lang.IllegalStateException: getDatabase called recursively
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.example.myapplication.database.database.onCreate(database.java:28) at
您正在SQLiteOpenHelper
的onCreate()
方法中调用getWritableDatabase()
。不要这样做-改用传递给您的onCreate()
方法的sqLiteDatabase
:
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String query = "CREATE TABLE IF NOT EXISTS " + tableName + "(" + ID_COL + " VARCHAR(50) PRIMARY KEY," + NAME_COL + " VARCHAR(50)," + EMAIL_COL + " VARCHAR(50)," + PASS_COL + " VARCHAR(50), "+MOBILE_COL+" VARCHAR(50));";
sqLiteDatabase.execSQL(query);
}
我正试图在詹金斯设置电子邮件通知 但当我点击测试配置时,我得到了下面的错误 请参考附件截图以及下面的错误 请帮帮我,我被困在这里了。 太阳安全供应商。certpath。SunCertPathBuilderException:找不到请求目标的有效证书路径 原因:sun.security.validator.验证器异常:PKIX路径构建失败 原因:javax。网ssl。SSLHandshakeExce
问题内容: 以下是我运行时遇到的错误: 问题答案: 在没有空格的路径中创建您的virtualenv环境。这就是为什么它发生的原因: 创建环境时,它会建立一个目录。在该目录中是与环境有关的所有可执行文件。有些是脚本。如您所知,hashbang用来告诉系统使用什么解释程序来运行脚本。您可能经常在脚本顶部看到此信息: 如果脚本位于,则告诉系统运行以下命令来执行脚本: 就您而言,virtualenv正在创
上一节展示了如何为ListOfNumbers类中的writeList方法编写异常处理程序。 有时,它适合代码捕获可能发生在其中的异常。 但在其他情况下,最好让一个方法进一步推给上层来调用堆栈处理异常。 例如,如果您将ListOfNumbers类提供为类包的一部分,则可能无法预期包的所有用户的需求。 在这种情况下,最好不要捕获异常,并允许一个方法进一步推给上层来调用堆栈来处理它。 如果writeLi
每当我从我的调用类时,我在行中得到 我知道这是最容易解决的例外,但我已经挣扎了一段时间,我需要帮助…任何人都可以给我一个提示,我错过了什么?
我试图运行一些Python脚本与库从一个基于miniconda/anaconda的docker容器,但我一直得到这个错误:。我还使用Python包装器为,以避免打开一个真正的Chrome窗口。 要(从正在运行的docker容器)复制此内容,请执行以下操作: 据此:https://sites.google.com/a/chromium.org/chromedriver/help/chrome-doe
问题内容: 我有一个使用socket.IO的node.js应用程序。它可以在http上正常工作,但是当尝试通过https连接到套接字时,没有任何反应。 这是代码的一部分: 和功能: 客户端连接如下: 正如我说的,在http上一切正常,但是在https上连接会给我“连接被中断”。我究竟做错了什么? 问题答案: 您不能像服务器那样初始化服务器。您必须启动一个单独的https服务器,然后将socket.