com.esri.arcgisruntime.ArcGISRuntimeException: Geodatabase is closed

709
1
08-26-2021 03:08 AM
AnkitKamboj
New Contributor

I am getting Geodatabase is closed error.  Below are callstack of error :-

com.esri.arcgisruntime.ArcGISRuntimeException: Geodatabase is closed.

at com.esri.arcgisruntime.internal.jni.CoreFeatureQueryResult.nativeIterator(Native Method)

at com.esri.arcgisruntime.internal.jni.CoreFeatureQueryResult.g(SourceFile:1)

at com.esri.arcgisruntime.data.FeatureQueryResult.iterator(SourceFile:4)

at aqmddev.aqmd.gov.scaqmdmobile.viewmodel.BaseViewModel.argGISService$lambda-4(BaseViewModel.kt:167)

at aqmddev.aqmd.gov.scaqmdmobile.viewmodel.BaseViewModel.$r8$lambda$DUDWFHLmsJ9MT2R8rukbngwex7g(Unknown Source:0)

at aqmddev.aqmd.gov.scaqmdmobile.viewmodel.BaseViewModel$$ExternalSyntheticLambda0.run(Unknown Source:4)

at android.os.Handler.handleCallback(Handler.java:938)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:223)

at android.app.ActivityThread.main(ActivityThread.java:7656)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

 

Here is my source code :-

protected fun argGISService(params: QueryParameters, url: String, response: (Int, feature: Set<Feature>?) -> Unit){

try{
// set all outfields
val outFields = arrayListOf<String>()
outFields.add("*")
params.isReturnGeometry = true
mServiceFeatureTable = ServiceFeatureTable(url)
mServiceFeatureTable!!.featureRequestMode = ServiceFeatureTable.FeatureRequestMode.MANUAL_CACHE
//populate the table based on the query, listen for result in a listenable future
//query feature from the table

val future = mServiceFeatureTable!!.populateFromServiceAsync(params, true, outFields)

future.addDoneListener {
try {
//call get on the future to get the result
val result = future.get()
val features = result.iterator().asSequence().toSet()

if (features != null && !features.isNullOrEmpty()) {
response(features.count(), features)
}else{
response(0, null)
}
}catch (e: Exception) {
response(0, null)
LogUtils.e("BaseFragment", "Populate from service failed 2: " + e.printStackTrace())

}catch (ex: RuntimeException){
LogUtils.e("BaseFragment", "runtime execptionPopulate from service failed 2: " + ex.printStackTrace())
ex.printStackTrace()
response(0, null)
}
}
}catch (e1: Exception){
e1.printStackTrace()
response(0, null)
}catch (ex2: RuntimeException){
ex2.printStackTrace()
response(0, null)
}
}

 

Tags (1)
0 Kudos
1 Reply
RamaChintapalli
Esri Contributor

Hi Ankit,

We have seen this error internally and it can happen when the ServiceFeatureTable goes out of scope/garbage collected on runtime platforms like android which is aggressive with garbage collection. When the SFT is disposed via garbage collection, the underlying geodatabase connection is also closed.

We fixed it for next release by making the FeatureQueryResult hold strong reference of ServiceFeatureTable and there by avoiding it being garbage collected easily. 

Currently we can make sure that ServiceFeatureTable instance is not garbage collected at the app level, by keeping a reference of ServiceFeatureTable within the future done listener of the populate method (ex: call any property on SFT like name etc.) or making the SFT and FeatureQueryResult class variables.

 

Thanks

Rama

0 Kudos