question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android M: Cannot make field constructor accessible

See original GitHub issue
D/Retrofit﹕java.lang.SecurityException: Can't make field constructor accessible
            at java.lang.reflect.Constructor.setAccessible(Constructor.java:334)
            at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:97)
            at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:79)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:82)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:92)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:92)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:92)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
            at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
            at com.google.gson.Gson.getAdapter(Gson.java:359)
            at com.google.gson.Gson.fromJson(Gson.java:809)
            at com.google.gson.Gson.fromJson(Gson.java:775)
            at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:63)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:367)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
            at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
            at retrofit.Platform$Android$2$1.run(Platform.java:142)
            at java.lang.Thread.run(Thread.java:818)

Originally filed at https://github.com/square/retrofit/issues/870.

Note: this might be a bug in the preview OS runtime and not Gson, but it’s definitely not a Retrofit problem.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:39 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
malinkangcommented, Mar 30, 2016

@jirivrany excludeFieldsWithoutExposeAnnotation()work for me

9reactions
nBollardcommented, Sep 23, 2015

I am using Retrofit and GSON in a project and only encountered this issue on Android M after replacing SugarORM with ActiveAndroid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android M + Retrofit + JSON : Can't make field constructor ...
1. I have tried this, now its not crashing at this point but its giving me all the null values in object where...
Read more >
Android M + Retrofit + JSON : Can't make field constructor ... - iTecNote
Android M + Retrofit + JSON : Can't make field constructor accessible. androidjsonretrofit. I am currently checking my app for M support.
Read more >
[Android Fix] Gson Cannot make field constructor accessible
[Android Fix] Gson Cannot make field constructor accessible ... like title the post, and I change my code to create Gson object bellow: ......
Read more >
Java.lang.SecurityException:Can ' t make Field constructor ...
Originally using Gsonconvertor, there is no problem on Android version 5.1.1, the result is switched to version 6.0.1, the following problem ...
Read more >
SimpleDateFormat - Android Developers
If week year 'Y' is specified and the calendar doesn't support any week years, ... If a DateFormatSymbols has been set explicitly with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found