我已经编写了一种在SQLite中更新用户密码的方法。
该方法是 updatePassword()
&:before {
content: '';
position: absolute;
width: 3em;
height: calc(100% + 3px);
right: calc(100% + 1px);
top: .4em;
transform: skewX(-20deg) rotate(-20deg);
transition: .3s;
}
当这个方法运行时,如果我注释掉SQL语句,它将显示Log,这表明它正在运行if语句而没有问题?
我也有toasts来显示if和#clans中使用的变量,但是它们显示了所需的值而且不是null!
一旦我回复public class changePassword extends Activity {
SQLiteDatabase checkDB;
//Load session name
String sessionName;
String sessionPassword;
String currentPasswordString;
String newPassword1String;
String newPassword2String;
//Load text fields
EditText currentPassword;
EditText newPassword1;
EditText newPassword2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.changepassword);
Button changePassword = (Button)findViewById(R.id.changePasswordButton);
//Load session name
SharedPreferences preferences = getSharedPreferences("temp", getApplicationContext().MODE_PRIVATE);
sessionName = preferences.getString("sessionName", "");
sessionPassword = preferences.getString("sessionPassword", "");
currentPassword = (EditText)findViewById(R.id.currentPassword);
newPassword1 = (EditText)findViewById(R.id.newpassword1);
newPassword2 = (EditText)findViewById(R.id.newpassword2);
}
//Mismatched password checking
public void updatePassword(View v)
{
currentPasswordString = currentPassword.getText().toString();
newPassword1String = newPassword1.getText().toString();
newPassword2String = newPassword2.getText().toString();
Toast.makeText(changePassword.this, sessionName.toString(), Toast.LENGTH_LONG).show();
Toast.makeText(changePassword.this, newPassword2String.toString(), Toast.LENGTH_LONG).show();
if (currentPasswordString.equals(sessionPassword))
{
if (newPassword1String.equals(newPassword2String))
{
checkDB.execSQL("UPDATE Students SET Student_Password=" + newPassword2String + "WHERE CNumber=" + sessionName);
Log.d("Password", "Changed");
}
}
}
}
,此LogCat错误就会显示:
execSQL
答案 0 :(得分:1)
如果您注释掉
checkDB.execSQL("UPDATE Students SET Student_Password=" + newPassword2String + "WHERE CNumber=" + sessionName);
行并运行到日志语句,然后checkDB
为null
。
您在哪里打开/初始化数据库?