2

Using Clarifai for Android getting error while invoking Clarifai

W/System.err: java.lang.RuntimeException: Failed to invoke clarifai2.dto.ClarifaiStatus() with no args
W/System.err:     at com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:94)
W/System.err:     at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:795)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:859)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:832)
W/System.err:     at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:249)
W/System.err:     at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:170)
W/System.err:     at com.example.amutgeka.visualclarifia.MainActivity.train(MainActivity.java:120)
W/System.err:     at com.example.amutgeka.visualclarifia.MainActivity$1$1.run(MainActivity.java:42)
W/System.err:     at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: java.lang.InstantiationException: Can't instantiate abstract class clarifai2.dto.ClarifaiStatus
W/System.err:     at java.lang.reflect.Constructor.newInstance0(Native Method)
W/System.err:     at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
W/System.err:     at `enter code here`com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:91)
W/System.err:   ... 9 more
Asmita09
  • 51
  • 7

1 Answers1

1

I maintain this library currently. The problem here is that ClarifaiStatus should not be instantiated directly (because it can't). If you look at the source code for the library, you can see that we register a Gson adapter that defines how to construct a ClarifaiStatus (in this case, by calling the constructor for AutoValue_ClarifaiStatus, which is auto-generated code).

For some reason, that adapter doesn't seem to be getting picked up; if it were, com.google.gson.internal.bind.ReflectiveTypeAdapterFactory wouldn't be getting invoked. So because no adapter is getting picked up, Gson falls back to its default behavior of trying to call the no-args constructor via reflection, which is impossible on an abstract class.

We haven't been able to reproduce this error, but we recently updated the client to support older versions of Gson, which might be the issue at hand. Can you make sure that you're using the latest version of the client, which is 2.2.3? Let me know if the issue persists.

kevinmost
  • 565
  • 1
  • 5
  • 7