我必须创建登录demo的SQLite应用程序。我已完成登录注册,并将数据插入数据库。现在我想插入数据表单注册登录或创建登录页面。当我运行我的应用程序时,我登录时,我得到nullPointerException。
以下是我的数据库适配器代码:
public String getSinlgeEntry(String userName)
{
Cursor cursor=db.query("REGISTER", null, " USERNAME=?", new String[]{userName}, null, null, null);
if(cursor.getCount()<1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex("PIN"));
cursor.close();
return password;
}
这是我的登录活动,我必须使用数据库适配器方法,如getSingleEntry
public class Application_Pin_Activity1 extends Activity
{
Button btnNewRegister;
Button btnLogin;
EditText editText_Email , editText_App_Pin;
String str_EmailId , str_AppPin;
LeadMgmt_DBAdapter leadMgmt_DataBaseAdapter;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.application_pin_activity1);
leadMgmt_DataBaseAdapter = new LeadMgmt_DBAdapter(this);
leadMgmt_DataBaseAdapter = leadMgmt_DataBaseAdapter.open();
editText_Email=(EditText)findViewById(R.id.edittext_enterEmail);
editText_App_Pin=(EditText)findViewById(R.id.editText_EnterPin);
btnLogin=(Button) findViewById(R.id.btn_Login);
btnLogin.setOnClickListener(new OnClickListener() {
@SuppressWarnings("unused")
public void onClick(View arg0) {
// TODO Auto-generated method stub
str_EmailId=editText_Email.getText().toString().trim();
str_AppPin=editText_App_Pin.getText().toString().trim();
// fetch the Password form database for respective user name
String storedApplication = leadMgmt_DataBaseAdapter.getSinlgeEntry(str_AppPin);
if(str_AppPin.equals(storedApplication))
{
Toast.makeText(Application_Pin_Activity1.this,"Access Allow", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Application_Pin_Activity1.this, "Sorry ! Wron Pin", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
// Close The Database
leadMgmt_DataBaseAdapter.close();
}
}