应用程序 activity 在更新 SQLite 数据库行时崩溃,并且在 flash previous activity 打开后

App activity crashes while updating SQLite database row and after flash previous activity opens

我第一个activity插入数据然后去第二个activity 第二个 Activity 使用 "A" 更新插入的行并转到第三个 activity 现在,......第三个 Activity activity 使用 B 更新同一行......但是这个 activity 只是在闪光后关闭并且第二次 activity 再次打开,除了每次不同编号的 PID 和 SIG:9 之外,日志什么也没有显示,每次都是一样的......代码更新和插入在这里

        public boolean updateForm1(String fake,String Res, String Gen,String rooms){

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues =new ContentValues();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if(Objects.equals(fake, "A")){
        contentValues.put(CoL_4,Res);
        contentValues.put(CoL_5,Gen);
        contentValues.put(CoL_6,rooms);
            db.update(TABLE_NAME,contentValues, "Residence = ?",new String[] { fake });
            db.close();}
        else if(Objects.equals(fake, "B")){
            contentValues.put(CoL_7,Res);
            contentValues.put(CoL_8,Gen);
            db.update(TABLE_NAME,contentValues, "Construction = ?",new String[] { fake });
            db.close();
        }
    }


    return true;
}

 public boolean insertData (String lat,String lng){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues =new ContentValues();
    contentValues.put(CoL_2,lat);
    contentValues.put(CoL_3,lng);
    contentValues.put(CoL_4,"A");
    contentValues.put(CoL_7,"B");
    long res =db.insert(TABLE_NAME,null,contentValues);
    db.close();
    return res != -1;



}

In Main Activity 这个函数正在插入

       private void goToLocationZoom(double lat, double lng, float zoom) {
    LatLng ll = new LatLng(lat, lng);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
    mGoogleMap.moveCamera(update);
}

Marker marker;


public void Tag(View view)  {

    MarkerOptions options = new MarkerOptions()
            .position(new LatLng(lat, lng))
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
    marker = mGoogleMap.addMarker(options);




    boolean isInserted = myDb.insertData(Double.toString(lat), Double.toString(lng));
    if (isInserted == true) {
        Toast.makeText(MainActivity.this, "Data Inserted", Toast.LENGTH_LONG).show();
    } else
    {Toast.makeText(MainActivity.this, "Data not Inserted", Toast.LENGTH_LONG).show();}
    intent =new Intent (this,Form1Activity.class);
    startActivity(intent);



}

第二个Activityyyyyy在这里eeeeeee.......

     public class Form1Activity extends AppCompatActivity {
private static RadioGroup radioGroup1,radioGroup2;
private static RadioButton Gr1Option,Gr2Option;
private static Button Enter;

DatabaseHelper myDbForm1;
private EditText Ed1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_form1);
    Enter();
}
public void Enter(){
    myDbForm1 = new DatabaseHelper(this);
    radioGroup1 = (RadioGroup) findViewById(R.id.RG1);
    radioGroup2 = (RadioGroup) findViewById(R.id.RG2);
    Enter= (Button) findViewById(R.id.enter1);

    Enter.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("WrongViewCast")
        @Override
        public void onClick(View v) {

            int selected1 =radioGroup1.getCheckedRadioButtonId();
            int selected2 =radioGroup2.getCheckedRadioButtonId();
            Gr1Option= (RadioButton) findViewById(selected1);
            Gr2Option= (RadioButton) findViewById(selected2);
            Ed1= (EditText) findViewById(R.id.editText1);
            if(Gr1Option== null || Gr2Option== null || Ed1==null )
            {
                Toast.makeText(Form1Activity.this,"Select one of the options", Toast.LENGTH_SHORT).show();
            }
            else {
                String a=Gr1Option.getText().toString();
                String b=Gr2Option.getText().toString();
                String c=Ed1.getText().toString();

                boolean isInserted = myDbForm1.updateForm1("A",a,b,c);
                if (isInserted) {
                    Toast.makeText(Form1Activity.this, "Data of form1 Inserted", Toast.LENGTH_LONG).show();
                } else
               {Toast.makeText(Form1Activity.this, "Data of form1 not Inserted", Toast.LENGTH_LONG).show();}

                Toast.makeText(Form1Activity.this, Gr1Option.getText().toString(), Toast.LENGTH_LONG).show();
                Toast.makeText(Form1Activity.this, Gr2Option.getText().toString(), Toast.LENGTH_LONG).show();
                Toast.makeText(Form1Activity.this, Ed1.getText().toString(), Toast.LENGTH_LONG).show();
            }

        }
    });


}

public void Next(View view){
    if(Gr1Option== null || Gr2Option== null|| Ed1==null )
    {
        Toast.makeText(Form1Activity.this,"Select one of the options and press Enter", Toast.LENGTH_SHORT).show();
    }
    else {
        Intent intent =new Intent(Form1Activity.this,Form2Activity.class);
        startActivity(intent);

    }

}

}

第三个 Activity 正在第二次更新行......

  public class Form2Activity extends AppCompatActivity {

private static RadioGroup radioGroup21,radioGroup22;
private static RadioButton Gr21Option,Gr22Option;
private static Button Enter2;

DatabaseHelper myDbForm2;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_form2);
    Enter2();
}

public void Enter2(){
    radioGroup21 = (RadioGroup) findViewById(R.id.RG21);
    radioGroup22 = (RadioGroup) findViewById(R.id.RG22);
    Enter2= (Button) findViewById(R.id.enter2);

    Enter2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int selected1 =radioGroup21.getCheckedRadioButtonId();
            int selected2 =radioGroup22.getCheckedRadioButtonId();
            Gr21Option= (RadioButton) findViewById(selected1);
            Gr22Option= (RadioButton) findViewById(selected2);
            if(Gr21Option== null || Gr22Option== null )
            {
                Toast.makeText(Form2Activity.this,"Select one of the options", Toast.LENGTH_LONG).show();
            }
            else
            {

                String a1=Gr21Option.getText().toString();
                String b1=Gr22Option.getText().toString();
                boolean isInserted = myDbForm2.updateForm1("B",a1,b1,"1");
                if (isInserted) {
                    Toast.makeText(Form2Activity.this, "Data of form2 Inserted", Toast.LENGTH_LONG).show();
                } else
                {Toast.makeText(Form2Activity.this, "Data of form2 not Inserted", Toast.LENGTH_LONG).show();}
                Toast.makeText(Form2Activity.this, Gr21Option.getText().toString(), Toast.LENGTH_LONG).show();
                Toast.makeText(Form2Activity.this, Gr22Option.getText().toString(), Toast.LENGTH_LONG).show();
            }

        }
    });


}

您还没有在第三个Activity

中初始化"myDbForm2"

这个功能现在对我有用

          public void Enter2(){


 myDbForm2 = new DatabaseHelper(this);
radioGroup21 = (RadioGroup) findViewById(R.id.RG21);
radioGroup22 = (RadioGroup) findViewById(R.id.RG22);
Enter2= (Button) findViewById(R.id.enter2);

Enter2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        int selected1 =radioGroup21.getCheckedRadioButtonId();
        int selected2 =radioGroup22.getCheckedRadioButtonId();
        Gr21Option= (RadioButton) findViewById(selected1);
        Gr22Option= (RadioButton) findViewById(selected2);
        if(Gr21Option== null || Gr22Option== null )
        {
            Toast.makeText(Form2Activity.this,"Select one of the options", Toast.LENGTH_LONG).show();
        }
        else
        {

            String a1=Gr21Option.getText().toString();
            String b1=Gr22Option.getText().toString();
            boolean isInserted = myDbForm2.updateForm1("B",a1,b1,"1");
            if (isInserted) {
                Toast.makeText(Form2Activity.this, "Data of form2 Inserted", Toast.LENGTH_LONG).show();
            } else
            {Toast.makeText(Form2Activity.this, "Data of form2 not Inserted", Toast.LENGTH_LONG).show();}
            Toast.makeText(Form2Activity.this, Gr21Option.getText().toString(), Toast.LENGTH_LONG).show();
            Toast.makeText(Form2Activity.this, Gr22Option.getText().toString(), Toast.LENGTH_LONG).show();
        }

    }
});

}