java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法

我的代码中出现以下错误可能是我遗漏了一些东西,我有另一个具有相同类型的代码并且工作正常:


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");

        }

慕莱坞森
浏览 216回答 1
1回答

狐的传说

您的变量“助手”似乎为空或未启用。你怎么称呼你的助手?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java