내 앱은 여러 가지 활동으로 구성되어 있습니다. 지금까지 활동간에 이동하는 동안 데이터베이스에 액세스하는 데 아무런 문제가 없었습니다. 그러나 마지막 listActivity (LocationActivity)에는 각 listView 항목에 포함 된 단추가 있습니다.활동간에 전환하는 동안 SQLite 데이터베이스에 액세스 할 때 예외가 발생했습니다.
이 버튼 중 하나를 클릭하면 사용자가 specView를 해당 listView 항목 (손상된 구성 요소)의 일부 EditText 필드에 입력하는 경우 SpecificationEdit.java로 이동하지만 저장을 클릭하면 다음 오류로 인해 충돌합니다 메시지 (데이터를 주 데이터베이스 확인에 저장됩니다) : 여기
java.lang.RuntimeException: Unable to resume activity blah blah
Exception: trying to requery an already closed cursor blah blah
는 listActivity 클래스입니다 :
public class LocationActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
setLongClick();
rmDbHelper = new RMDbAdapter(this);
rmDbHelper.open();
getIntents();
setUpViews();
setAdapter();
setTextChangedListeners();
}
protected void onResume(){
super.onResume();
final Cursor locationCursor = (Cursor) rmDbHelper.fetchLocationsForRun(runId);
startManagingCursor(locationCursor);
locationCursorSize = locationCursor.getCount();
setAdapter();
setTextChangedListeners();
}
그리고 여기이 활동의 비트가 SpecificationEdit.java
당신을 보낸다 당신은 저장 버튼을 클릭하면 발사 코드의 비트와@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rmDbHelper = new RMDbAdapter(this);
rmDbHelper.open();
Intent i = getIntent();
inspectionId = i.getLongExtra("Intent_InspectionID", -1);
areaId = i.getLongExtra("Intent_AreaID", -1);
runId = i.getLongExtra("Intent_RunID", -1);
locationId = i.getLongExtra("Intent_LocationID", -1);
damagedComponentId = i.getLongExtra("Intent_DamagedComponentID", -1);
setContentView(R.layout.edit_specification);
setUpViews();
populateFields();
fillSpinner();
setListeners();
}
: 마지막으로
protected void saveDamagedComponentSpec() {
String manufacturer = ((Cursor)manufacturerSpinner.getSelectedItem()).getString(1).toString();
String text1 = specEditText1.getText().toString();
String text2 = specEditText2.getText().toString();
String text3 = specEditText3.getText().toString();
String text4 = specEditText4.getText().toString();
String notes_spec = specEditTextNotes.getText().toString();
rmDbHelper.saveDamagedComponentSpec(damagedComponentId, manufacturer, text1, text2, text3, text4, notes_spec);
if ("Yes".equals(specSaved)){
Toast.makeText(getApplicationContext(), "Component specification updated",
Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "Component specification added",
Toast.LENGTH_SHORT).show();
}
finish();
}
을, 여기에 코드입니다 16,
private void startComponentEdit() {
Intent i = new Intent(LocationActivity.this, SpecificationEdit.class);
i.putExtra("Intent_InspectionID", inspectionId);
i.putExtra("Intent_AreaID", areaId);
i.putExtra("Intent_RunID", runId);
i.putExtra("Intent_LocationID", locationId);
i.putExtra("Intent_Ref", locationRef);
i.putExtra("Intent_DamagedComponentID", damagedComponentId);
startActivityForResult(i, ACTIVITY_CREATE);
}
그리고 여기가 SpecificationEdit.java의 한 OnCreate입니다 데이터베이스 도우미 클래스에서 :
//Constructor - takes the context to allow the database to be opened/created
public RMDbAdapter(Context ctx) {
this.mCtx = ctx;
}
/**
* Open the rm database. If it cannot be opened, try to create a new
* instance of the database. If it cannot be created, throw an exception to
* signal the failure
*
* @return this (self reference, allowing this to be chained in an
* Initialisation call)
* @throws SQLException if the database could be neither opened or created
*/
public RMDbAdapter open() throws SQLException {
rmDbHelper = new DatabaseHelper(mCtx);
rmDb = rmDbHelper.getWritableDatabase();
return this;
}
public void close() {
rmDbHelper.close();
}
새 항목은 listView 항목 (포함 된 항목이 아닌 실제 항목) 또는 '새 구성 요소 추가'버튼 중 하나를 클릭하면 매우 유사한 인터페이스로 다른 활동 인 ComponentEdit.java로 이동합니다 (구성 요소를 추가하기 위해 목록으로)을 SpecificationEdit으로 설정하지만 완료되면 앱을 다운시키지 않습니다.
두 활동간에 큰 차이는 보이지 않지만 LocationActivity로 돌아 왔을 때이 오류로 인해 충돌이 발생합니다.
나는 방금 onResume을 제거해 보았습니다. 그리고 이것은 아무런 차이가 없었습니다. 이것으로 벽돌 벽을 치면 나에게 너트가 몰리게됩니다.
내 에뮬레이터에서 정상적으로 작동한다고 추가해야하지만 휴대 전화 (HTC One S)에서 테스트 할 때 충돌이 발생합니다. 아주 이상해 ..
수동으로 locationCursor를 닫으시겠습니까? – nandeesh
빠른 응답 nandeesh을 보내 주셔서 감사합니다. 코드를 업데이트했지만 아무런 차이가 없습니다. – Scamparelli
startManagingCursor를 사용하는 경우 절대 커서를 닫지 말고 작업을 수행해야합니다.너를 위해 그것의 배려 – nandeesh