I use this code in my android studio project:
HttpUrl url = new HttpUrl.Builder().scheme("http").host("www.somesite.com")
.addPathSegment("kontakt")
.addQueryParameter("yit_contact[imie]", name)
.addQueryParameter("yit_contact[email]", email)
.addQueryParameter("yit_contact[telefon]", telephone)
.addQueryParameter("yit_contact[wiadomosc]", message)
.addQueryParameter("yit_bot", "")
.addQueryParameter("_wp_http_referer", "/kontakt/").build();
Request request = new Request.Builder().url(url).build();
Response response = new OkHttpClient().newCall(request).execute();
and I get this error when I try to get Response object:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.VerifyError: com/squareup/okhttp/internal/http/HttpConnection$AbstractSource
at com.squareup.okhttp.internal.http.HttpConnection.newFixedLengthSource(HttpConnection.java:246)
at com.squareup.okhttp.internal.http.HttpTransport.getTransferStream(HttpTransport.java:125)
at com.squareup.okhttp.internal.http.HttpTransport.openResponseBody(HttpTransport.java:110)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:926)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
at com.squareup.okhttp.Call.getResponse(Call.java:274)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
at com.squareup.okhttp.Call.execute(Call.java:81)
at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:135)
at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:87)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
I have added jar files to project:
compile files('libs/okhttp-2.4.0.jar')
compile files('libs/okio-1.0.0.jar')
Help.
Try adding Okio-1.4.0, which is required by OkHttp 2.4.0.
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.4.0</version>
</dependency>
Related
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.mime.HttpMultipartMode
at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:91)
at com.greencubes.greendesk.AndroidMultiPartEntity.<init>(AndroidMultiPartEntity.java:19)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.uploadFile(FirstFragment.java:244)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.doInBackground(FirstFragment.java:233)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.doInBackground(FirstFragment.java:211)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
If you are using a library, you need to put it into /libs folder.
download httpmime, httpcore and httpclient library from http://hc.apache.org/downloads.cgi
Hope this will help as i have the same jar files in the studio.
If you are using Eclipse then add all the jar files to build path.
Thanks,
Apache HTTP client was removed in Lollipop. It's recommended to use HttpUrlConnection instead.
If you have to use it you can add:
android {
useLibrary 'org.apache.http.legacy'
}
to your build.gradle file.
I am encountering the exception stated below in my android code where I am trying to parse an ODATA service using odata4j JAR library.
java.lang.IllegalArgumentException: Illegal datetime format 2015-05-07T00%3A00%3A00
I am getting the error at line below in Android code:
List list = c.getEntities("EntityName").execute().toList();
My entire stacktrace is stated below:
Caused by: java.lang.IllegalArgumentException: bad valueString [datetime'2015-05-07T00%3A00%3A00'] as part of keyString [*****='*****',*****='0',***='*****',date=datetime'2015-05-07T00%3A00%3A00',*****='*******']
at org.odata4j.core.OEntityKey.parse(OEntityKey.java:157)
at org.odata4j.format.xml.AtomFeedFormatParser.parseEntityKey(AtomFeedFormatParser.java:300)
at org.odata4j.format.xml.AtomFeedFormatParser.entityFromAtomEntry(AtomFeedFormatParser.java:431)
at org.odata4j.format.xml.AtomFeedFormatParser.parseEntry(AtomFeedFormatParser.java:349)
at org.odata4j.format.xml.AtomFeedFormatParser.parseFeed(AtomFeedFormatParser.java:169)
at org.odata4j.format.xml.AtomFeedFormatParser.parse(AtomFeedFormatParser.java:157)
at org.odata4j.format.xml.AtomFeedFormatParser.parse(AtomFeedFormatParser.java:45)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.doRequest(ConsumerQueryEntitiesRequest.java:67)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.getEntries(ConsumerQueryEntitiesRequest.java:50)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.execute(ConsumerQueryEntitiesRequest.java:40)
at *******.MyActivity$LoadSpinners.doInBackground(MyActivity.java:287)
at *******.MyActivity$LoadSpinners.doInBackground(MyActivity.java:202)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.IllegalArgumentException: Illegal datetime format 2015-05-07T00%3A00%3A00
at org.odata4j.internal.InternalUtil.parseDateTimeFromXml(InternalUtil.java:96)
at org.odata4j.expression.ExpressionParser.readExpression(ExpressionParser.java:462)
at org.odata4j.expression.ExpressionParser.parse(ExpressionParser.java:64)
at org.odata4j.core.OEntityKey.parse(OEntityKey.java:152)
There are ****** placed at certain sensitive information like not related properties and app package names.
I am getting this issue most of the time in samsung devices while sending sms.
Android version
Android 4.0.3 - 4.0.4
This is the error report I'm getting
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1333)
at android.os.Parcel.readException(Parcel.java:1281)
at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:644)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:149)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:99)
at com.msh7.utilities.SMSSender$SMSProgressTask.doInBackground(SMSSender.java:87)
at com.msh7.utilities.SMSSender$SMSProgressTask.doInBackground(SMSSender.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
On line 87, I have this code
sms.sendTextMessage(destinationNumber, null, msg, sentPI, deliveredPI);
and all this method is inside the AsyncTask's doInBackground() method.
Could anyone please help me in this?
*Note : My App sends sms in the background and it's not a default sms app.
I guess it's due to over size limit of text. Max allowed characters are 159. So you have to divide message into parts and send it.
Dude you are getting NullPointerException. Seems like you have not initialized sms object.
Please check..
Well in program, I am using In app billing. After QueryInventoryFinishedListener I want to change user interface. So I made like this. but it gives this error.
#Override
protected Void doInBackground(Void... params) {
mHelper.queryInventoryAsync(mGotInventoryListener);
return null;
}
#Override
protected void onPostExecute(Void result) {
updateUserinterface();
super.onPostExecute(result);
}
E/AndroidRuntime(26593): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(26593): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(26593): at android.os.AsyncTask$3.done(AsyncTask.java:299)
E/AndroidRuntime(26593): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(26593): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(26593): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(26593): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(26593): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/AndroidRuntime(26593): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/AndroidRuntime(26593): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/AndroidRuntime(26593): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(26593): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
If I didnt use doInBacground() class sometimes some premium stuff showing like not purchased already. I want to prevent this. Do you have any idea?
"After QueryInventoryFinishedListener I want to change user interface."
So why you don't do it then?
You are updating UI in onPostExecute, not in onQueryInventoryFinished...why not?
Besides, .queryInventoryAsync() runs in background, that's why it's called Async... no need for another background thread around it.
I used android account manager for twitter authorization as given in
How to retrieve Twitter and facebook Authentication and Token through Android's Account Manager classes
generated access token and secret in android app. but i am not able to post a tweet using those token, secret got following errors : No authentication challenges found.any solution for this
at:No authentication challenges found
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=1b442895
TwitterException{exceptionCode=[b2b52c28-1b442895 b2b52c28-1b44286b],
statusCode=-1, retryAfter=-1, rateLimitStatus=null,
featureSpecificRateLimitStatus=null, version=2.2.5}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:200)
attwitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
attwitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1929)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:433)
at com.example.sharemessageusingservice.TwitterPost$updateTwitterStatus.doInBackground (TwitterPost.java:340) 01-30 16:50:49.907:
at com.example.sharemessageusingservice.TwitterPost$updateTwitterStatus.doInBackground
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.io.IOException: No authentication challenges found
01-30
at libcore.net.http.HttpURLConnectionImpl.getAuthorizationCredentialsHttpURLConnectionImpl.java:427)
at libcore.net.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:407)
at libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:356)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
t libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34)
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:141)