Select to view content in your preferred language

Facing issue while syncing point to geodatabase

572
1
06-05-2023 03:40 AM
komalzoting
Emerging Contributor

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

 

0 Kudos
1 Reply
Shubham_Sharma
Esri Contributor

Based on your code seems like you are using the "Add features (feature service)" sample as your example code. To me the code seems right and might need some debugging based on the error message you received. "Invalid call.: Can only call this method on a loaded table."

Would recommend checking to see if the ServiceFeatureTable has been loaded before adding a point feature to the table:

// create a feature layer using the first layer in the geodatabase
val serviceFeatureTable = getTable(0)
if (serviceFeatureTable.loadStatus == LoadStatus.LOADED) {
// add point feature here...
} else if (serviceFeatureTable.loadStatus == LoadStatus.FAILED_TO_LOAD) {
logToUser(
true,
"Error loading service feature table: ${serviceFeatureTable.loadError.message}"
)
}

 

 

0 Kudos