我正在创建一个基于登录活动的应用程序。当我进行注册(注册)时,所有数据都成功进入数据库,但是当用户处于登录活动并尝试登录时,异常中为空。
这是我的代码,
loginuserid=etloginuserid.getText().toString();
loginpassword=etloginpassword.getText().toString();
try
{
String storedPassword=db.getPasswordOfThisUser(loginuserid);
if(loginpassword.equals(storedPassword))
{
Toast.makeText(getApplicationContext(), "Login Successfull", Toast.LENGTH_SHORT).show();
Intent iwelpage=new Intent(this,WelcomeActivity.class);
startActivity(iwelpage);
finish();
break;
}
else
{
Toast.makeText(getApplicationContext(), "Username or Password does not match!", Toast.LENGTH_SHORT).show();
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
这是我的数据库类活动,
创建表时,
public void onCreate(SQLiteDatabase db)
{
try
{
String CREATE_POLLINGDATA_TABLE="CREATE TABLE pollingdata(username TEXT, userid PRIMARY KEY, password TEXT)";
db.execSQL(CREATE_POLLINGDATA_TABLE);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
在检索输入的用户 ID 的密码时,
public String getPasswordOfThisUser(String loginuserid)
{
Cursor cursor=db.query("pollingdata", null, " userid=?" , new String[]{loginuserid}, null, null, null);
if(cursor.getCount()<1)
{
cursor.close();
return "Not Exist";
}
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex(KEY_PASSWORD));
return password;
}
日志猫,
10-30 06:03:13.066: E/AndroidRuntime(13692): FATAL EXCEPTION: main
10-30 06:03:13.066: E/AndroidRuntime(13692): java.lang.NullPointerException
10-30 06:03:13.066: E/AndroidRuntime(13692): at com.example.polling.LoginActivity.onClick(LoginActivity.java:47)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.view.View.performClick(View.java:4204)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.view.View$PerformClick.run(View.java:17355)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.os.Handler.handleCallback(Handler.java:725)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.os.Handler.dispatchMessage(Handler.java:92)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.os.Looper.loop(Looper.java:137)
10-30 06:03:13.066: E/AndroidRuntime(13692): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-30 06:03:13.066: E/AndroidRuntime(13692): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 06:03:13.066: E/AndroidRuntime(13692): at java.lang.reflect.Method.invoke(Method.java:511)
10-30 06:03:13.066: E/AndroidRuntime(13692): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-30 06:03:13.066: E/AndroidRuntime(13692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-30 06:03:13.066: E/AndroidRuntime(13692): at dalvik.system.NativeStart.main(Native Method)
我哪里错了?
请帮我,
谢谢。