Hii All,
I have loaded map using portal item. I want to sync point geodatabase but its showing error that is "Can only call this method on a loaded table."
code snippet is given bellow
// Loading map using portal item
val portal = Portal("https://arcgisruntime.maps.arcgis.com/")
val portalItem = PortalItem(portal, "fb788308ea2e4d8682b9c05ef641f273")
map = ArcGISMap(portalItem)
ServiceGeodatabase(service_layer_url).apply {
loadAsync()
addDoneLoadingListener {
// create a feature layer using the first layer in the geodatabase
serviceFeatureTable = getTable(0)
}
}
// syncing point to database
private fun addFeature(mapPoint: Point, featureTable: ServiceFeatureTable) {
// create default attributes for the feature
hashMapOf<String, Any>(
"typdamage" to "Destroyed",
"primcause" to "Earthquake"
).let { attributes ->
// creates a new feature using default attributes and point
featureTable.createFeature(attributes, mapPoint)
}.let { feature ->
// check if feature can be added to feature table
if (featureTable.canAdd()) {
// add the new feature to the feature table and to server
featureTable.addFeatureAsync(feature).addDoneListener { applyEdits(featureTable) }
} else {
logToUser(true, getString(R.string.error_cannot_add_to_feature_table))
}
}
}
/**
* Sends any edits on the ServiceFeatureTable to the server.
*
* @param featureTable service feature table
*/
private fun applyEdits(featureTable: ServiceFeatureTable) {
// apply the changes to the server
featureTable.serviceGeodatabase.applyEditsAsync().let { editResult ->
editResult.addDoneListener {
try {
editResult.get()?.let { edits ->
// check if the server edit was successful
edits.firstOrNull()?.let {
if (!it.editResult[0].hasCompletedWithErrors()) {
logToUser(false, getString(R.string.feature_added))
} else {
it.editResult[0].error
}
}
}
} catch (e: ArcGISRuntimeException) {
logToUser(true, getString(R.string.error_applying_edits, e.cause?.message))
}
}
}
}
//error
com.esri.arcgisruntime.ArcGISRuntimeException: Invalid call.: Can only call this method on a loaded table.
at com.esri.arcgisruntime.internal.jni.CoreFeatureTable.nativeCreateFeatureWithAttributes(Native Method)
at com.esri.arcgisruntime.internal.jni.CoreFeatureTable.a(SourceFile:13)
at com.esri.arcgisruntime.data.FeatureTable.createFeature(SourceFile:4)
at com.example.identifypopup.MainActivity.addFeature(MainActivity.kt:616)
at com.example.identifypopup.MainActivity.onCreate$lambda$8(MainActivity.kt:281)
Please help