I make a new feature table in mobile gdb by Kotlin API as follow :
val tableDescription = TableDescription("landuse", SpatialReference.wgs84(), GeometryType.Point)
tableDescription.fieldDescriptions.addAll(
listOf(
FieldDescription("oid", FieldType.Oid),
FieldDescription("time", FieldType.Date),
FieldDescription("fclass", FieldType.Text)
)
)
geodatabase?.createTable(tableDescription)?.onSuccess {
println("Success!")
}?.onFailure {
println("Failed: ${it.message}.")
}
By now, everything is all right.
And then, insert a feature:
private suspend fun createFeature() {
val featureAttributes = mutableMapOf<String, Any>()
featureAttributes["fclass"] = "farm"
featureAttributes["time"] = Calendar.getInstance()
val feature = featureTable?.createFeature(featureAttributes, Point(115.799745, 39.044125))
featureTable?.addFeature(feature!!)?.onSuccess {
println("Success!")
}?.onFailure {
println("Failed: ${it.message}.")
}
}
A Exception has been ocurred :
2022-12-23 12:34:44.162 14428-14428/edu.hebtu.geodatabase E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.hebtu.geodatabase, PID: 14428
java.lang.IllegalStateException: Cannot convert to core element
at com.arcgismaps.internal.coreextensions.CoreElementExtensionsKt.getCoreElement(CoreElementExtensions.kt:1980)
at com.arcgismaps.internal.coreextensions.CoreElementExtensionsKt$toElementLambda$200.invoke(CoreElementExtensions.kt:1303)
at com.arcgismaps.internal.coreextensions.CoreElementExtensionsKt$toElementLambda$200.invoke(CoreElementExtensions.kt:1303)
at com.arcgismaps.internal.platformextensions.PlatformExtensionsKt.createCoreDictionary(PlatformExtensions.kt:103)
at com.arcgismaps.data.FeatureTable.createFeature(FeatureTable.kt:283)
at edu.hebtu.geodatabase.MainActivity$onCreate$3$1$2$1.invokeSuspend(MainActivity.kt:108)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
Why was that happened! I have tried LocalDataTime, TimeStamp objects, but those all did not work!
Thank you!
Solved! Go to Solution.
Hey @DongYu ,
FieldType.Date now takes a Kotlinx date-time instant instead of the Java Util Calendar class. Check out the API ref for more info on FieldType
So in your code, the field type would look like:
import kotlinx.datetime.Clock
featureAttributes["time"] = Clock.System.now()
Hey @DongYu ,
FieldType.Date now takes a Kotlinx date-time instant instead of the Java Util Calendar class. Check out the API ref for more info on FieldType
So in your code, the field type would look like:
import kotlinx.datetime.Clock
featureAttributes["time"] = Clock.System.now()