Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: Field 'elementType' is not found in class java.util.EnumSet #3

Closed
davide1995 opened this issue Sep 6, 2018 · 4 comments

Comments

@davide1995
Copy link

Hello.
I'm using your library in my android project. Actually, I've a smartphone and a tablet. In my smartphone
(v8.0), all works fine (version 8.0), but in my tablet (v4.4) an exception is thrown.

09-06 23:54:43.264 9766-9766/com.experiment.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.experiment.myapp, PID: 9766
    java.lang.ExceptionInInitializerError
        at com.gilecode.yagson.com.google.gson.internal.Excluder.<clinit>(Excluder.java:71)
        at com.gilecode.yagson.YaGson.<init>(YaGson.java:91)
        at com.experiment.myapp.global.PersonsMobilizations.PersonsMobilizationsPresenter.checkDetailRuleForPersonAtPosition(PersonsMobilizationsPresenter.java:45)
        at com.experiment.myapp.global.PersonsMobilizations.PersonMobilizationViewHolder.onClick(PersonMobilizationViewHolder.java:59)
        at android.view.View.performClick(View.java:4463)
        at android.view.View$PerformClick.run(View.java:18770)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5292)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: Field 'elementType' is not found in class java.util.EnumSet
        at com.gilecode.yagson.types.TypeUtils.getDeclaredField(TypeUtils.java:405)
        at com.gilecode.yagson.types.TypeUtils.<clinit>(TypeUtils.java:435)
        at com.gilecode.yagson.com.google.gson.internal.Excluder.<clinit>(Excluder.java:71) 
        at com.gilecode.yagson.YaGson.<init>(YaGson.java:91) 
        at com.experiment.myapp.global.PersonsMobilizations.PersonsMobilizationsPresenter.checkDetailRuleForPersonAtPosition(PersonsMobilizationsPresenter.java:45) 
        at com.experiment.myapp.global.PersonsMobilizations.PersonMobilizationViewHolder.onClick(PersonMobilizationViewHolder.java:59) 
        at android.view.View.performClick(View.java:4463) 
        at android.view.View$PerformClick.run(View.java:18770) 
        at android.os.Handler.handleCallback(Handler.java:808) 
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:5292) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.NoSuchFieldException: elementType
        at java.lang.Class.getDeclaredField(Class.java:596)
        at com.gilecode.yagson.types.TypeUtils.getDeclaredField(TypeUtils.java:401)
        at com.gilecode.yagson.types.TypeUtils.<clinit>(TypeUtils.java:435) 
        at com.gilecode.yagson.com.google.gson.internal.Excluder.<clinit>(Excluder.java:71) 
        at com.gilecode.yagson.YaGson.<init>(YaGson.java:91) 
        at com.experiment.myapp.global.PersonsMobilizations.PersonsMobilizationsPresenter.checkDetailRuleForPersonAtPosition(PersonsMobilizationsPresenter.java:45) 
        at com.experiment.myapp.global.PersonsMobilizations.PersonMobilizationViewHolder.onClick(PersonMobilizationViewHolder.java:59) 
        at android.view.View.performClick(View.java:4463) 
        at android.view.View$PerformClick.run(View.java:18770) 
        at android.os.Handler.handleCallback(Handler.java:808) 
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:5292) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
        at dalvik.system.NativeStart.main(Native Method)

Exception is thrown during the initialization of YaGson

YaGson gson = new YaGson();

@davide1995 davide1995 changed the title ava.lang.IllegalStateException: Field 'elementType' is not found in class java.util.EnumSet java.lang.IllegalStateException: Field 'elementType' is not found in class java.util.EnumSet Sep 6, 2018
@amogilev
Copy link
Owner

amogilev commented Sep 8, 2018

Hi,

At first, thank you for your report and your interest in YaGson.
Please test the fix at https://github.com/amogilev/yagson/releases/download/v0.4-fix1/yagson-0.5-SNAPSHOT.jar. If it worked, I'll add it to the new release.

However, please note that YaGson was never tested on Android. And, it has much more dependencies to the structure of standard Java Library classes than the original Gson, which was the reason of this issue. Thus, it is possible that there are some other incompatibilities, which could potentially result in further exceptions or errors.

I will try to test YaGson with some Android emulator, but it may take a longer time, as I have no Android experience at all.

Also, could you please share with us why you have chosen YaGson for your Android apps. In particular, which YaGson features are important for you, and which are not. Thanks!

@davide1995
Copy link
Author

davide1995 commented Sep 10, 2018

Unfortunately, your fix does not completely solve the problem. In fact now there is another exception:

09-10 13:24:05.504 20338-20338//com.experiment.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.experiment.myapp, PID: 20338
    java.lang.IllegalStateException: Failed to initialize ThreadTypesAdapterFactory
        at com.gilecode.yagson.adapters.ThreadTypesAdapterFactory.<init>(ThreadTypesAdapterFactory.java:91)
        at com.gilecode.yagson.com.google.gson.Gson.<init>(Gson.java:270)
        at com.gilecode.yagson.YaGson.<init>(YaGson.java:91)
        at com.experiment.myapp.global.PersonsMobilizations.PersonsMobilizationsPresenter.checkDetailRuleForPersonAtPosition(PersonsMobilizationsPresenter.java:45)
        at com.experiment.myapp.global.PersonsMobilizations.PersonMobilizationViewHolder.onClick(PersonMobilizationViewHolder.java:59)
        at android.view.View.performClick(View.java:4463)
        at android.view.View$PerformClick.run(View.java:18770)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5292)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)

The exception is thrown always during object initialization

I decided to use YaGson because it is really near to Gson and has circular reference (present in my project). I know there is also Jackson, but I find a little bit boring to annotate the circular class. Moreover, for such a "simple" task, I find that three jars are a bit too many. My choice then falls on YaGson although currently to avoid the problem I'm using Jackson. When you solve the bug, I will re-enable the YaGson serialization code

@amogilev
Copy link
Owner

amogilev commented Oct 6, 2018

Fixed in release 0.4.1

@amogilev amogilev closed this as completed Oct 6, 2018
@davide1995
Copy link
Author

Checked and I confirm the bug is resolved! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants