我的代码中出现以下错误可能是我遗漏了一些东西,我有另一个具有相同类型的代码并且工作正常:
java.lang.NullPointerException: 尝试调用虚拟方法'long app.akexorcist.bluetoothspp.DatabaseHelper.insertData(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang .String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)' 在一个空对象上参考
以下是一些代码:
谢谢
public void postDataToSQLite() { SharedPreferences sharedpreferences = getSharedPreferences(LoginActivity.MyPREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor 编辑器 = sharedpreferences.edit();
SharedPreferences vehiclesharedpreferences = getSharedPreferences(VehicleEntryActivity.MyVehicle, Context.MODE_PRIVATE);
SharedPreferences.Editor vehicle_editor = sharedpreferences.edit();
String name = txtName.getText().toString();
String surname = txtSurname.getText().toString();
String idno = txtIDNo.getText().toString();
String birth = txtDateBirth.getText().toString();
String username = sharedpreferences.getString(Name, "");
editor.apply();
String make = vehiclesharedpreferences.getString(Make, "");
String colour = vehiclesharedpreferences.getString(Colour, "");
String expiry = vehiclesharedpreferences.getString(Expiry, "");
String regno = vehiclesharedpreferences.getString(RegNo, "");
String date = vehiclesharedpreferences.getString(DateTime, "");
String loc = vehiclesharedpreferences.getString(GPS, "");
vehicle_editor.apply();
String event = "Entry";
if(name.isEmpty() || surname.isEmpty() || idno.isEmpty() || birth.isEmpty())
{
Toast.makeText(this, "Please scan drivers licence", Toast.LENGTH_SHORT).show();
}
else
{
long id = helper.insertData(make,colour,expiry,regno,date,loc,name,surname,idno,birth,event,username);
Intent intent = null;
if(id<=0)
{
Message.message(getApplicationContext(),"Failed... Please Check Data");
}
狐的传说
相关分类