everybody.
I have a situation when my object that I'm receiving from server can be in multiple types. It could be an empty ArrayList or some Object type with filled values, depends on different situations.
That is why I get an GSON error
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:161)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 360 path $.user_fields
So, the final question is how to construct object right on client side to convert the response from server in simplest way with GSON lib?
Related
I'm using Okhttp:3.4.1 . Using this, all the https calls were giving
java.net.protocolexception: expected ':status' header not present.
Some of blogs advised to update Okhttp. When I update from 3.4.1 to 3.10.0, I'm getting
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.NoSuchMethodError: No virtual method setCallWebSocket(Lokhttp3/Call;)V in class Lokhttp3/internal/Internal; or its super classes (declaration of 'okhttp3.internal.Internal' appears in /data/app/com.XXXXXX.android-1/split_lib_dependencies_apk.apk:classes85.dex)
at okhttp3.ws.WebSocketCall.enqueue(WebSocketCall.java:108)
at com.facebook.react.devsupport.InspectorPackagerConnection$Connection.connect(InspectorPackagerConnection.java:243)
at com.facebook.react.devsupport.InspectorPackagerConnection.connect(InspectorPackagerConnection.java:44)
at com.facebook.react.devsupport.DevServerHelper$3.doInBackground(DevServerHelper.java:204)
at com.facebook.react.devsupport.DevServerHelper$3.doInBackground(DevServerHelper.java:200)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
I'm using react-native:0.45.1
React native use okhttp as a dependency, upgrade okhttp may result in some compatibility issue. Currently it's using okhttp 3.6.0 (https://github.com/facebook/react-native/blob/8466db0fd355aea778ff71cfb10c927cfd18a551/ReactAndroid/build.gradle#L288). So my advice is that just leave it be.
Getting this error in sample app.
java.net.ProtocolException: Expected HTTP 101 response but was '401
Not Authorized'
Using this code snippet to transalate.
TranslateOptions translateOptions = new TranslateOptions.Builder()
.addText(params[0])
.source(Language.ENGLISH)
.target(selectedTargetLanguage)
.build();
TranslationResult translationResult = translationService
.translate(translateOptions)
.execute();
Once it executes the application crashes and I see this error in logs.
D/OkHttp: --> POST https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate http/1.1 (46-byte body)
D/OkHttp: <-- 401 Not Authorized https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate (413ms, unknown-length body)
POST https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate, status: 401, error: Not Authorized
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.gobiggi.watsontutorial, PID: 10136
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by:
com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials. Tip: Did you set the Endpoint?
at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:410)
at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:174)
at com.gobiggi.watsontutorial.MainActivity$TranslationTask.doInBackground(MainActivity.java:328)
at com.gobiggi.watsontutorial.MainActivity$TranslationTask.doInBackground(MainActivity.java:321)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
i don't know too much about how watson sdk works but just by looking at the error i see:
com.ibm.watson.developer_cloud.service.exception.UnauthorizedException:
Unauthorized: Access is denied due to invalid credentials. Tip: Did
you set the Endpoint?
Is saying the credentials presented are not valid. You should start by looking at that.
I use helpshift in my app and catch this crash.
It happened in some device, but not all.
Please, help me fix this crash.
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802)
Error Code : 1802 (SQLITE_IOERR_FSTAT)
Caused By : Failed to get database file information with system call stat(). Please confirm whether database file has been removed.
(disk I/O error (code 1802))
at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:683)
at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:527)
at com.helpshift.storage.KeyValueDbStorage.set(KeyValueDbStorage.java:81)
at com.helpshift.model.SdkInfoModel.setFirstLaunch(SdkInfoModel.java:141)
at com.helpshift.campaigns.controllers.DeviceController.onBackground(DeviceController.java:300)
at com.helpshift.app.MainLifecycleCallback$1.run(MainLifecycleCallback.java:44)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
You need to call
db = dbHelper.getWritableDatabase();
this in your constructor of your database class
Following the example provided here:
https://developers.google.com/gmail/api/v1/reference/users/messages/send#examples
email.setText() throws a NoClassDefFoundException:
Process: com.slickapp.www.slicklikeapp, PID: 19125
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoClassDefFoundError: javax.activation.DataHandler
at javax.mail.internet.MimeMessage.setContent(MimeMessage.java:1428)
at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:1029)
at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1467)
at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1451)
at com.slickapp.www.slicklikeapp.ComposeEmailActivity$SendEmailTask.doInBackground(ComposeEmailActivity.java:153)
at com.slickapp.www.slicklikeapp.ComposeEmailActivity$SendEmailTask.doInBackground(ComposeEmailActivity.java:113)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Finding solutions in the following links:
java.lang.NoClassDefFoundError: javax.activation.DataHandler
java.lang.NoClassDefFoundError: javax.activation.DataHandler in android
I understand that this exception is due to android not implementing java.awt.datatransfer classes. I tried the solutions but they didnt work. When i added javax.mail 1.5.5 in gradle it shows a duplicate file copied error.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/mimetypes.default
File1: C:\Users\Taha\.gradle\caches\modules-2\files-2.1\com.sun.mail\android-activation\1.5.6\34c941857c08ff1d6af9a43a8806342883b2a8e1\android-activation-1.5.6.jar
File2: C:\Users\Taha\.gradle\caches\modules-2\files-2.1\javax.activation\activation\1.1\e6cb541461c2834bdea3eb920f1884d1eb508b50\activation-1.1.jar
I couldnt find any solutions for this. I tried excluding excluding file in gradle packaging options, it didnt work only throwing NoClassDefFound exception again.
Any help would be appreciated.
I am facing the following exception when i try to call method on server, can any one tell me what is the problem ?
stacktrace
java.io.FileNotFoundException: https://services.q84sale.com/live/index.php/V1/Users/register
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246)
com.forsale.forsale.controller.manager.ForSaleNetworkManager.execute(ForSaleNetworkManager.java:116)
com.forsale.forsale.controller.manager.ForSaleServerManager$18.doInBackground(ForSaleServerManager.java:1423)
com.forsale.forsale.controller.manager.ForSaleServerManager$18.doInBackground(ForSaleServerManager.java:1399)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:848)
Too little information for right answer. Probably:
You specified an object with in your query that doesn't exist on server
You are using wrong method (GET, PUT) instead of POST
Server has some errors in its code
Add:
I noticed you are using .getInputStream() after receiving response code above 399. Check .getResponseCode() and then use .getErrorStream() instead