Jetpack Compose Breaking GSON - android

I have an working Android project whenever I add Jetpack Compose Dependencies my GSON is not working as expected. The Strange things if I remove excludeFieldsWithModifiers or if I don't use any inheritance for the classes which I am parsing using GSON then it's working.
Steps to Reproduce:
Add Jetpack Compose Runtime or Jetpack Compose Dependencies
Add GSON Dependencies
Use GsonBuilder to create GSON Object and add excludeFieldsWithModifiers option
Create a simple class hierarchy
Try to parse any json using to Child class which you have created above using the same GSON Object (Created in Step 3)
For Illustration purpose I am adding one sample
class Response(#SerializedName("id") var id : Int = 0) : BaseResponse()
open class BaseResponse
val gsonMapper: Gson by lazy {
GsonBuilder()
.excludeFieldsWithModifiers(
java.lang.reflect.Modifier.TRANSIENT. // Can you any other modifier
)
.create()
}
fun responseProcess() {
try {
val response = """{"id": 3}"""
val data = gsonMapper.fromJson(response, Response::class.java)
Log.d(TAG, "responseProcess: $data")
} catch (e: Exception) {
e.printStackTrace()
}
}
StackTrace for the above Code
2022-11-30 18:14:12.162 14856-14856/com.bhaskar.myapplication W/System.err: java.lang.IllegalArgumentException: class com.bhaskar.myapplication.Response declares multiple JSON fields named $stable
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.Gson.fromJson(Gson.java:926)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.Gson.fromJson(Gson.java:892)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.Gson.fromJson(Gson.java:841)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.google.gson.Gson.fromJson(Gson.java:813)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.bhaskar.myapplication.MainActivityKt.responseProcess(MainActivity.kt:74)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.bhaskar.myapplication.MainActivityKt$Greeting$1$1.invoke(MainActivity.kt:54)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at com.bhaskar.myapplication.MainActivityKt$Greeting$1$1.invoke(MainActivity.kt:53)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.foundation.ClickableKt$clickable$4$gesture$1$2.invoke-k-4lQ0M(Clickable.kt:153)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.foundation.ClickableKt$clickable$4$gesture$1$2.invoke(Clickable.kt:142)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.foundation.gestures.TapGestureDetectorKt$detectTapAndPress$2$1$1.invokeSuspend(TapGestureDetector.kt:223)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:178)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328)
2022-11-30 18:14:12.163 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter$PointerEventHandlerCoroutine.offerPointerEvent(SuspendingPointerInputFilter.kt:511)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.dispatchPointerEvent(SuspendingPointerInputFilter.kt:406)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.onPointerEvent-H0pRuoY(SuspendingPointerInputFilter.kt:419)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:310)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:297)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:297)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.NodeParent.dispatchMainEventPass(HitPathTracker.kt:179)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.kt:98)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-BIzXfog(PointerInputEventProcessor.kt:80)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.platform.AndroidComposeView.sendMotionEvent-8iAsVTc(AndroidComposeView.android.kt:1159)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.platform.AndroidComposeView.handleMotionEvent-8iAsVTc(AndroidComposeView.android.kt:1109)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent(AndroidComposeView.android.kt:1059)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3594)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3594)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3594)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3594)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:915)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1957)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at android.app.Activity.dispatchTouchEvent(Activity.java:4182)
2022-11-30 18:14:12.164 14856-14856/com.bhaskar.myapplication W/System.err: at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:873)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.View.dispatchPointerEvent(View.java:15458)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:7457)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7233)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6595)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6786)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6843)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9880)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9718)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9671)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:10014)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
2022-11-30 18:14:12.165 14856-14856/com.bhaskar.myapplication W/System.err: at android.os.MessageQueue.nativePollOnce(Native Method)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at android.os.MessageQueue.next(MessageQueue.java:335)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at android.os.Looper.loop(Looper.java:206)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:8633)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
2022-11-30 18:14:12.166 14856-14856/com.bhaskar.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Thank You

By calling excludeFieldsWithModifiers you overwrite the default modifier exclusions. Therefore now you (accidentally?) include static fields, and $stable seems to be a synthetic field added by the compiler (not sure though why Gson is not detecting that it is synthetic).
You can solve this by adding Modifier.STATIC to the modifiers as well:
excludeFieldsWithModifiers(Modifier.TRANSIENT or Modifier.STATIC)
(though note that this is effectively the same as the default Gson field exclusion)
If you need to serialize static fields for some reason, then you might have to write a custom ExclusionStrategy to ignore the unwanted $stable field.

Related

Android app, http request to ip address fails

I have simple "gadget" based on Arduino. It is connected to the wlan of my house and sending web requests to it turns on/off a red LED indicating that I'm busy/free in my room. This works fine when called from a browser or from my small winforms application. It is called synchronous, it is just enough, no need for async calls.
But, I tried to create a android app that sends the same requests, no success. I have read many topics, tried different ways etc. The app has this row in manifest file:
android:networkSecurityConfig="#xml/network_security_config"
Maybe something is still missing. This might be very very basic, but I haven't been able to get it working. Code:
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.buttonFirst.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
OkHttpClient client = new OkHttpClient();
String url = "http://192.168.100.12/LED=ON";
Request req = new Request.Builder()
.url(url)
.build();
try {
client.newCall(req).execute();
} catch (IOException | RuntimeException e) {
e.printStackTrace();
}
NavHostFragment.findNavController(FirstFragment.this)
.navigate(R.id.action_FirstFragment_to_SecondFragment);
}
});
}
It fails on execute call. The app enters the catch section, but there's no understandable description in e. And of course, my mobile phone is connected to the same wlan.
Stack trace:
I/System.out: port:80
W/System.err: android.os.NetworkOnMainThreadException
W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:389)
W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
W/System.err: at java.net.Socket.connect(Socket.java:631)
W/System.err: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.kt:63)
W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
W/System.err: at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
W/System.err: at com.example.donotdisturb.FirstFragment$1.onClick(FirstFragment.java:52)
W/System.err: at android.view.View.performClick(View.java:6603)
W/System.err: at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
W/System.err: at android.view.View.performClickInternal(View.java:6576)
W/System.err: at android.view.View.access$3100(View.java:780)
W/System.err: at android.view.View$PerformClick.run(View.java:26088)
W/System.err: at android.os.Handler.handleCallback(Handler.java:873)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err: at android.os.Looper.loop(Looper.java:193)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6705)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

Gluon, Android 10 Black screen issue

Code is working fine for Android 8 and 9, this issue only in Android 10. We can run in Android 10 by using the command adb shell settings put global hidden_api_policy 1. But this is again only device or Emulator specific. Is there any general solution to fix this issue for Android 10.
W/System.err: java.lang.reflect.InvocationTargetException
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
W/System.err: at java.lang.Thread.run(Thread.java:923)
W/System.err: Caused by: java.lang.RuntimeException: Exception in Application start method
W/System.err: at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
W/System.err: at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)
W/System.err: at com.sun.javafx.application.LauncherImpl.access$lambda$1(Unknown Source:8)
W/System.err: at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source:13)
W/System.err: ... 1 more
W/System.err: Caused by: java.lang.NoSuchMethodError: No static method getLogger(Ljava/lang/String;)Lsun/util/logging/PlatformLogger; in class Lsun/util/logging/PlatformLogger; or its super classes (declaration of 'sun.util.logging.PlatformLogger' appears in /apex/com.android.art/javalib/core-oj.jar)
W/System.err: at com.sun.javafx.util.Logging.getCSSLogger(Logging.java:98)
W/System.err: at com.sun.javafx.css.parser.CSSParser.<clinit>(CSSParser.java:164)
W/System.err: at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1079)
W/System.err: at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:910)
W/System.err: at com.sun.javafx.css.StyleManager._addUserAgentStylesheet(StyleManager.java:1263)
W/System.err: at com.sun.javafx.css.StyleManager.setUserAgentStylesheets(StyleManager.java:1204)
W/System.err: at com.sun.javafx.application.PlatformImpl.lambda$_setPlatformUserAgentStylesheet$165(PlatformImpl.java:698)
W/System.err: at com.sun.javafx.application.PlatformImpl.access$lambda$13(Unknown Source:2)
W/System.err: at com.sun.javafx.application.PlatformImpl$$Lambda$14.run(Unknown Source:4)
W/System.err: at java.security.AccessController.doPrivileged(AccessController.java:43)
W/System.err: at com.sun.javafx.application.PlatformImpl._setPlatformUserAgentStylesheet(PlatformImpl.java:697)
W/System.err: at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:548)
W/System.err: at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
W/System.err: at javafx.scene.control.Control.<clinit>(Control.java:86)
W/System.err: at com.gluonhq.charm.glisten.application.MobileApplication.start(SourceFile:202)
W/System.err: at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$145(LauncherImpl.java:863)
W/System.err: at com.sun.javafx.application.LauncherImpl.access$lambda$8(Unknown Source:4)
W/System.err: at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source:7)
W/System.err: at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)
W/System.err: at com.sun.javafx.application.PlatformImpl.access$lambda$6(Unknown Source:4)
W/System.err: at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source:7)
W/System.err: at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
W/System.err: at com.sun.javafx.application.PlatformImpl.access$lambda$18(Unknown Source:2)
W/System.err: at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source:4)
W/System.err: at java.security.AccessController.doPrivileged(AccessController.java:59)
W/System.err: at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
W/System.err: at com.sun.javafx.application.PlatformImpl.access$lambda$5(Unknown Source:4)
W/System.err: at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source:7)
W/System.err: at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:93)
W/System.err: at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:52)
Below is the gradle file code of application, have added the dependency and configuration and per document.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.12'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.Sample'
dependencies {
compile 'com.gluonhq:charm:5.0.0'
}
jfxmobile {
downConfig {
version = '3.8.0'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
I used com.gluonhq.charm.down.common.PlatformFactory package insteed of com.gluonhq.attach.util.Platform for jfxmobile-plugin 1x versions. works fine

java.lang.IllegalArgumentException while using GSON

I have this line of code
val event = Gson().fromJson(socketResponse.toString(), com.spaxiappuser.service.booking.event.Event::class.java)
Which throws the error
java.lang.IllegalArgumentException: class android.widget.TextView
declares multiple JSON fields named mMinWidth
My data class is as follows
data class Event(
val tripParams: TripParams? = null,
val onDemand: OnDemand? = null,
#SerializedName("request_id")
val requestId: String? = null,
#SerializedName("driver_userid")
val driverId: String? = null,
val due: Due? = null,
val standard: Standard? = null,
val isToAllowBackPress: Boolean = false
Can anyone please let me know why this is happening?
Here is my stack trace :
W/System.err: java.lang.IllegalArgumentException: class android.widget.TextView declares multiple JSON fields named mMinWidth
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:926)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:892)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:841)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:813)
W/System.err: at com.spaxiappuser.service.socket.EventManager.handleEvent(EventManager.kt:35)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$2.accept(Listener.kt:78)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$2.accept(Listener.kt:15)
W/System.err: at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onNext(ObservableDoOnEach.java:93)
W/System.err: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onNext(ObservableSubscribeOn.java:58)
W/System.err: at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onNext(ObservableCreate.java:66)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$1.subscribe(Listener.kt:50)
W/System.err: at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:12197)
W/System.err: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
W/System.err: at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:919)
Any help in identifying the issue will be much appreciated.
One of the classes your model references has a TextView somewhere in it (or extends TextView), and GSON is trying to interpret that as a class to be inflated from JSON.
Find it and either mark that field transient, or otherwise exclude that field.

why wont my LocalDate.parse work with a value inserted from gson?

I have a class:
data class Day(val date: String, val events: List<Event>){
val localDateTimeDate: LocalDate by lazy {
LocalDate.parse(date)
}
}
This gets filled from a JSON string (eg. {"date": "2019-06-26", "events": []}.
If I read someDay.date, I get "2019-06-26", so the filling part works.
If I read someDay.localDateTimeDate, I get a nullpointer exception, and I don't see why.
Now, if I go in REPL and fill a "Day" by hand (ie. val day = Day("2019-06-26"", emptyList()) this works.
If I make my android phone do LocalDate.parse("2019-06-26"), that works.
Day gets filled by:
fun receiveDays(): List<Day> {
val listType = object : TypeToken<List<Day>>() { }.type
val jsonData = (client.readFromSocket()!!.message).toString(Charsets.UTF_8)
val daysList =(Gson().fromJson<List<Day>>(jsonData, listType))
client.sendOK()
return daysList
If I try to read someDay.localDateTimeDate, I get a nullpointer exception:
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object kotlin.Lazy.getValue()' on a null object reference
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at nl.joozd.joozdter.data.Day.getLocalDateTimeDate(Unknown Source:25)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at nl.joozd.joozdter.ui.PdfParserActivity$onCreate$$inlined$let$lambda$1.invoke(PdfParserActivity.kt:140)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at nl.joozd.joozdter.ui.PdfParserActivity$onCreate$$inlined$let$lambda$1.invoke(PdfParserActivity.kt:28)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt:143)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Unknown Source:0)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at org.jetbrains.anko.AsyncKt$sam$java_util_concurrent_Callable$0.call(Unknown Source:2)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-08-13 00:06:13.075 21870-21942/nl.joozd.joozdter W/System.err: at java.lang.Thread.run(Thread.java:764)
If a class doesn't have parameterless constructor, Gson creates an object without calling the constructor, thus the field that stores lazy delegate doesn't get initialized and you get a NullPointerException when accessing the property delegated to it.
See also this question for the possible solutions: Why Kotlin data classes can have nulls in non-nullable fields with Gson?

Retrofit 2.0 multipart file uploading sendto failed: ETIMEDOUT (Connection timed out) error

I increased the timeout of okhttp client to 5 minutes:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(5, TimeUnit.MINUTES);
client.setReadTimeout(5, TimeUnit.MINUTES);
client.setWriteTimeout(5, TimeUnit.MINUTES);
client.interceptors().add(new Interceptor() {
#Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
// Customize the request
Request request = original.newBuilder()
//.header("Accept", "application/json")
.header("Authorization", Constants.SERVICE_AUTH_KEY)
.method(original.method(), original.body())
.build();
// Customize or return the response
return chain.proceed(request);
}
});
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.SERVICE_URL)
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
I use WCF Webservice, i also increased the timeout time to same thing.
Everything works perfectly fine, but uploading file or image to the server.
Even after increasing timeout on both Android and WCF, I still get the error on android:
java.net.SocketException: sendto failed: ETIMEDOUT (Connection timed
out)
This is the full log
W/System.err: java.net.SocketException: sendto failed: ETIMEDOUT (Connection timed out)
W/System.err: at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:550)
W/System.err: at libcore.io.IoBridge.sendto(IoBridge.java:519)
W/System.err: at java.net.PlainSocketImpl.write(PlainSocketImpl.java:511)
W/System.err: at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
W/System.err: at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
W/System.err: at okio.Okio$1.write(Okio.java:80)
W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:46)
W/System.err: at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.writeAll(RealBufferedSink.java:104)
W/System.err: at com.squareup.okhttp.RequestBody$3.writeTo(RequestBody.java:118)
W/System.err: at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeOrCountBytes(MultipartBuilder.java:277)
W/System.err: at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeTo(MultipartBuilder.java:297)
W/System.err: at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:887)
W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
W/System.err: at com.squareup.okhttp.Call.getResponse(Call.java:268)
W/System.err: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
W/System.err: at com.mbh.mbhportal.network.NewPortalService$1.intercept(NewPortalService.java:59)
W/System.err: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
W/System.err: at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
W/System.err: at com.squareup.okhttp.Call.execute(Call.java:79)
W/System.err: at retrofit.OkHttpCall.execute(OkHttpCall.java:116)
W/System.err: at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:111)
W/System.err: at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:88)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:8098)
W/System.err: at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
W/System.err: at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err: at java.lang.Thread.run(Thread.java:838)
W/System.err: Caused by: libcore.io.ErrnoException: sendto failed: ETIMEDOUT (Connection timed out)
W/System.err: at libcore.io.Posix.sendtoBytes(Native Method)
W/System.err: at libcore.io.Posix.sendto(Posix.java:151)
W/System.err: at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
W/System.err: at libcore.io.IoBridge.sendto(IoBridge.java:517)
W/System.err: ... 40 more
What timeout is this ETIMEDOUT !?

Categories

Resources