gpt4 book ai didi

java - 错误: constructor for a xyz class is not defined

转载 作者:行者123 更新时间:2023-12-01 23:58:10 25 4
gpt4 key购买 nike

public class MainActivity extends Activity {

private String md5(String in) {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(in.getBytes());
byte[] a = digest.digest();
int len = a.length;
StringBuilder sb = new StringBuilder(len << 1);
for (int i = 0; i < len; i++) {
sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
sb.append(Character.forDigit(a[i] & 0x0f, 16));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
EditText text = (EditText) findViewById(R.id.editText1);
EditText text1 = (EditText) findViewById(R.id.editText2);
String userid = text.getText().toString();
String pass = text1.getText().toString();

Toast.makeText(
MainActivity.this,
"Entered " + userid + " and password entered is "
+ pass, Toast.LENGTH_LONG).show();

pass = md5(pass + "@string/salt");

Toast.makeText(
MainActivity.this,
"Password after adding a salt and md5 hashing is now equal to "
+ pass, Toast.LENGTH_LONG).show();

/* This Line */DBAdapter db = new DBAdapter(this); // This Line.
db.open();
Cursor c = db.getPasswordForUserName(userid);
if (c.moveToFirst()) {
if (c.getString(1) == pass) {
Toast.makeText(MainActivity.this,
"Authentication Succeded", Toast.LENGTH_SHORT)
.show();
// proceed
} else {
Toast.makeText(MainActivity.this, "@string/AuthFail",
Toast.LENGTH_SHORT).show();
// AuthFailure
}
} else {
Toast.makeText(MainActivity.this, "@string/UserNotFound",
Toast.LENGTH_SHORT).show();
// where to from here
}
}
});
}
}

我对 Android 编程非常陌生。所以我从很多地方获取了代码 fragment ,然后将它们组合起来。

基本上我想做的就是查询本地 SQLite 数据库以获取 UserName 的现有值和Password + salt(with md5 hash) .

因此,我复制了一些代码来创建一个数据库帮助程序类 ( DBAdapter ),它具有非常基本的方法来处理数据库。

现在的问题是在 MainActivity.java文件。代码中标记为“这一行”的行给出错误构造函数 DBAdapter(new View.OnClickListener(){}) 未定义。我不知道这意味着什么。我应该怎么做才能让它发挥作用?

最佳答案

我只能猜测尝试 MainActivity.this ,有预感..

DBAdapter db = new DBAdapter(MainActivity.this);

关于java - 错误: constructor for a xyz class is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com