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
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.
Related
I have a simple POST request for registering a location in our backend which should respond a string with the locationId and an unique registration code which gets shown for other stuff. In Postman the request looks like: 120:B6IRDAEDZ82BCDMP9QUK which is fine.
So, I've built a retrofit request which simply does the same:
#POST("remote_montage/set_credentials/{locationId}")
suspend fun getRegistrationQrCode(
#Path("locationId") locationId: Int
): Response<String>
Now, if I call it in my repository, it throws me this Error
com.google.gson.stream.MalformedJsonException: Expected value at line 1 column 4 path $
W/System.err: at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1568)
W/System.err: at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:590)
W/System.err: at com.google.gson.stream.JsonReader.peek(JsonReader.java:425)
W/System.err: at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:41)
W/System.err: at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
W/System.err: at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
W/System.err: at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:153)
W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
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:923)
I have no Idea what this means. What Columns? What value? What Line?
The GsonConverterFactory you are providing to retrofit is looking at the response and finding that it is invalid JSON.
You should use ScalarsConverterFactory which is designed to convert string responses
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
and add it to your retrofit builder
.addConverterFactory(ScalarsConverterFactory.create())
I have this exception in my app, under warnings in the Logcat.
The app is a system app.
java.lang.reflect.InvocationTargetException
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at netchanger.tawkon.com.lib.network.NetworkChanger.setPreferredNetwork(NetworkChanger.java:48)
W/System.err: at netchanger.tawkon.com.lib.network.NetworkChanger.setPreferredNetwork(NetworkChanger.java:36)
W/System.err: at netchanger.tawkon.com.lib.services.LocationMonitorService.stopService(LocationMonitorService.java:57)
W/System.err: at com.tawkon.data.lib.service.KeepAliveService$PowerReceiver.onReceive(KeepAliveService.java:154)
W/System.err: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1313)
W/System.err: at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
W/System.err: at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
W/System.err: at android.os.Handler.handleCallback(Handler.java:790)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err: at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6494)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
W/System.err: Caused by: java.lang.SecurityException: No Carrier Privilege.
W/System.err: at android.os.Parcel.readException(Parcel.java:2005)
W/System.err: at android.os.Parcel.readException(Parcel.java:1951)
W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.setPreferredNetworkType(ITelephony.java:4237)
W/System.err: at android.telephony.TelephonyManager.setPreferredNetworkType(TelephonyManager.java:4821)
W/System.err: ... 15 more
I see that this is InvocationTargetException and it's caused by SecurityException.
What does 'No Carrier Privilege.' mean? How can I avoid this?
Security Exception implies there is a permission required to which the user hasn't granted. Ensure you request for the correct permission and confirm that the user has granted the permission before execution of the functionality.
Read on telephony manager
As per the android documentation in order to use android.telephony.TelephonyManager.setPreferredNetworkType() method your app should have carrier privileges.
Carrier Privileges in a gist:
Android grants special privileges to apps from Mobile (Virtual) Network Operator (MNO/MVNOs) via UICC to override certain carrier configurations (e.g. IMS settings) on the device. This app from operator is signed with a signing key whose hash value is stored in UICC, which is in-turn read by Android Platform to allow the app to make calls to handful of special APIs
More information related to how to give your app carrier privileges can be found here. The link explains the method to override IMS settings using carrier privileges but it can be applied to whatever functionality you are trying to achieve
After getting facebook access token, i use it for login in my own web server. However in the first time, there is warning in the log file, and i can not load data from my server, but when i open app from second times, it load normally.
Below is warning log:
W/System.err: com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
at line 1 column 1 path $ W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
W/System.err: at
retrofit2.ServiceMethod.toResponse(ServiceMethod.java:122)
W/System.err: at
retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:217) W/System.err:
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) W/System.err:
at
retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42) W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(SingleDoOnSuccess.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
W/System.err: at
io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:579)
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:764)
W/System.err: Caused by: java.lang.IllegalStateException: Expected
BEGIN_OBJECT but was STRING at line 1 column 1 path $ W/System.err:
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)
What could be causing this?
That error tells you that there is an error when GSON tries to parse the JSON returned by the web service you're calling. In particular, GSON is expecting a JSON object, but it receives a string (see the first line of the error message).
If the error happens only the first time you call it and not the second it means that the web service returns 2 different answers, and GSON can correctly parse the second one, but not the first one.
In order to find out what's wrong, you should provide more details, like your data model and the 2 responses returned by the web service.
I know this type of question has been asked before and i have gone through this but still facing this issue. I was using this example . But while i run my code i got following exception
Failed to detect whether we are running on Google Compute Engine.
java.net.ConnectException: Failed to connect to /169.254.169.254:80
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:104)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.auth.oauth2.ComputeEngineCredentials.runningOnComputeEngine(ComputeEngineCredentials.java:191)
at com.google.auth.oauth2.DefaultCredentialsProvider.tryGetComputeCredentials(DefaultCredentialsProvider.java:270)
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized(DefaultCredentialsProvider.java:194)
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:112)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:134)
at com.google.cloud.dialogflow.v2.stub.GrpcSessionsStub.create(GrpcSessionsStub.java:75)
at com.google.cloud.dialogflow.v2.stub.SessionsStubSettings.createStub(SessionsStubSettings.java:100)
at com.google.cloud.dialogflow.v2.SessionsClient.(SessionsClient.java:132)
at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:114)
at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:106)
at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.detectIntentStream(MainActivity.java:76)
at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.doInBackground(MainActivity.java:61)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
W/System.err: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
W/System.err: at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:119)
W/System.err: at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
W/System.err: at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
W/System.err: at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53)
W/System.err: at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:134)
W/System.err: at com.google.cloud.dialogflow.v2.stub.GrpcSessionsStub.create(GrpcSessionsStub.java:75)
W/System.err: at com.google.cloud.dialogflow.v2.stub.SessionsStubSettings.createStub(SessionsStubSettings.java:100)
W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.(SessionsClient.java:132)
W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:114)
W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:106)
W/System.err: at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.detectIntentStream(MainActivity.java:76)
W/System.err: at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.doInBackground(MainActivity.java:61)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)
from where can i set environment variable in android studio, I am windows user
From the error
java.io.IOException: The Application Default Credentials are not
available. They are available if running in Google Compute Engine.
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS
must be defined pointing to a file defining the credentials
See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.
You may need to add this in the environment variable path GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service_accont_key_file.json. And should get the json file from here https://cloud.google.com/docs/authentication/getting-started . Also if you don't know how to set environment variable path you can check this https://www.computerhope.com/issues/ch000549.htm
I am implementing Facebook Login in my App but its not working on Api 2.3.6
I have tested the App in Emulator and its working Fine upto Api 23
Also it's working in Device with API 21 but not in 2.3.6
The Error is related to SSL
Bcoz I have read in an SO answer that,
in Api level 2.3.6 all connections and authorizations are handled by HTTPS only
while in Api levels above 2.3.6 its not the HTTPS that does every task
Also I have noticed that whenever I am trying to call any URL starting
with HTTPS it's not giving the final result but gets silently stopped as was the case
with Googles Direction Api.
Below is the StackTrace I am getting in 2.3.6 :
V/webkit: LoadListener.handleSslErrorRequest():
url:https://m.facebook.com/v2.4/dialog/oauth?
return_scopes=true&response_type=token%2Csigned_request&redirect_uri
=fbconnect%3A%2F%2Fsuccess&display=touch&sdk=android-
4.5.1&e2e=%7B%22init%22%1232%7D&client_id=1234&default_audience=friends
primary error: 3 certificate: Issued to: CN=*.facebook.com,O=Facebook\,
Inc.,L=Menlo Park,ST=CA,C=US;
Issued by: 1.2.840.113549.1.9.1=#1223,CN=Cyberoam SSL
CA_C016700030,OU=Cyberoam Certificate
Authority,O=Elitecore,L=Ahmedabad,ST=Gujarat,C=IN;
I/System.out: close [socket][/0.0.0.0:52994]
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
W/System.err: at
com.facebook.login.LoginManager.onActivityResult(LoginManager.java:173)
W/System.err: at
com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:139)
W/System.err: at
com.facebook.internal.CallbackManagerImpl.onActivityResult
(CallbackManagerImpl.java:82)
W/System.err: at
com.hogo.integrationapp.FirstActivity.onActivityResult
(FirstActivity.java:179)
W/System.err: at
android.app.Activity.dispatchActivityResult(Activity.java:3975)
W/System.err: at
android.app.ActivityThread.deliverResults(ActivityThread.java:2629)
W/System.err: at
android.app.ActivityThread.handleSendResult(ActivityThread.java:2675)
W/System.err: at
android.app.ActivityThread.access$2000(ActivityThread.java:156)
W/System.err: at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1030)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:130)
W/System.err: at android.os.Looper.loop(SourceFile:351)
W/System.err: at
android.app.ActivityThread.main(ActivityThread.java:3821)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:538)
W/System.err: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run\
(ZygoteInit.java:969)
W/System.err: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
Is there any Easy way to solve it ?
Also I want to understand why this is happening ?
I am using Facebook Sdk 4.5.1
For API 4.4.2 :
The Error was due to a File Transfer App open in my Device, when i closed it the error was gone
Thanks in Advance...