Select to view content in your preferred language

Can't insert features which contains Date field in mobile geodatabase .

643
1
Jump to solution
12-22-2022 08:43 PM
DongYu
by
New Contributor

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!

 

 

0 Kudos
1 Solution

Accepted Solutions
Shubham_Sharma
Esri Contributor

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()

 

 

View solution in original post

1 Reply
Shubham_Sharma
Esri Contributor

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()