Multiple enqueue in retrofit causing out of memory error? - android

Am doing my project using retrofit2. When my Call goes on failure i repeat same call again.Repeation of this call made my app to force close.
When i look on log i got error log, which is given below. I felt this is caused by multiple enqueue to same Call. So i did that before enqueus i called cancel. But its not working. getting same force close.
FATAL EXCEPTION: main
Process: com.SocialMob, PID: 27846
java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
at java.lang.VMThread.create(Native Method)
at java.lang.Thread.start(Thread.java:1029)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
at okhttp3.Dispatcher.enqueue(Dispatcher.java:112)
at okhttp3.RealCall.enqueue(RealCall.java:78)
at okhttp3.RealCall.enqueue(RealCall.java:70)
at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:104)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.enqueue(ExecutorCallAdapterFactory.java:58)
at com.SocialMob.Activities.SplashActivity.VersionCheck(SplashActivity.java:184)
at com.SocialMob.Activities.SplashActivity.access$500(SplashActivity.java:38)
at com.SocialMob.Activities.SplashActivity$1.onFailure(SplashActivity.java:177)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$2.run(ExecutorCallAdapterFactory.java:75)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Thanks in advance.

You should avoid that approach, as it would make it a recursive call. Instead you should check the cause in the failure function first and then retry. Also fix the number of retry times.

I am using Retrofit 2.0.2, and i have this tag in my manifest file:
android:largeHeap="true"
I am retrying on failure like this:
#Override
public void onFailure(Call<AudioResponse> call, Throwable error) {
loading.setVisibility(View.GONE);
if (mAdapter.getItemCount() == 0) {
SetErrorContent();
}
Log.e("Error", error.getMessage() + "");
call.cancel();
call.clone().enqueue(this);
}
It is not crashing.Give it a try.

Related

Java lang Verify error in call to constructor in my app

I am creating a thread in the following manner:
GraphThread thread = new GraphThread(context, handler, string);
Note that handler is a static Handler object, which could be causing the problem. I have been getting an error exactly at this line of code. But, the error does not appear in other virtual devices such as API 23 and 25, as well as my physical device(Nougat).
I did try to set up a try{}catch block, but it is not catching the exception, which is unusual. The stack trace is as follows:
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException**
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick**(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:4438) 
at android.view.View$PerformClick.run(View.java:18422) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.VerifyError: noodlesoup/solver/GraphThready
at noodlesoup.solver.MainActivity.clikButton(MainActivity.java:4985)
It comes down to java.lang Verifyerror that I believe is created by passing the parameter static Handler. I don't know why this is happening in API 19 virtual device and not in the other virtual device which I have tested.
Any ideas or suggestions?
After reading through many posts, I came across the following idea: The void run method in my Thread class was too complex. There were too many variables defined inside the run method; There were too many decisions to make in a method that contained over 4000 lines of code. The post and answer that gave me the idea was the following
VerifyError - Verifier rejected class
So, all I had to do was create extra methods within the Thread class were the sum of
their work was equal to the 4000+ lines of code inside the run method.
In the end the Thread class structure looks like this, and it compiles without no more verify errors:
public class GraphThready extends Thread{
//...
GraphThready(){
//...
}
public void run(){
super.run();
if(some condition)
methodToDoTask1();
if(another condition)
methodToDoTask2();
if(a different condition)
methodToDoTask3();
}
private void methodToDoTask1(){
}
private void methodToDoTask2(){
}
private void methodToDoTask3(){
}
}

Getting java.lang.VerifyError after upgrading to Android Studio 2.0

I upgraded Android Studio to 2.0.
Then when I run & debug the app, it works fine until I click a button and call a function, and java.lang.VerifyError is thrown. This is what I get from logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fronty.zt, PID: 18022
java.lang.VerifyError: com/fronty/zt/SilverCord$AjcClosure11
at com.fronty.zt.SilverCord.checkEmailExistence(SilverCord.java:407)
at com.fronty.zt.register.RegisterBasicActivity.onClick(RegisterBasicActivity.java:122)
at com.fronty.zt.register.RegisterBasicActivity$$ViewBinder$1.doClick(RegisterBasicActivity$$ViewBinder.java:26)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
This is checkEmailExistence():
#DebugLog
public void checkEmailExistence(StringPacket pack, final Response.Listener<ResponseBase> listener, Response.ErrorListener errorListener)
{
request("checkEmailExistence", ResponseBase.class, listener, errorListener, "/api/v0/check_email_existence", pack);
}
But when I set a breakpoint and follow, it actually goes deeper before it throws. checkEmailExistence() calls request() and the exception is thrown at the first line inside request()
if ( doLog )
Log.i( T, function );
I tried deleting build dir, rebuild, clean.. & etc with no effect.
However, changing gradle version fixes the problem:
classpath 'com.android.tools.build:gradle:2.0.0'
to
classpath 'com.android.tools.build:gradle:1.5.0'
But this will disable Instant Run, so I would like to stick to 2.0.0. Does anyone know the cause or how to go about this?
Thanks!
I get the same error.I think it is hugo lead to the problem . Don't use #DebugLog,I run my app without the problem

app crashes when it queries to hosted parse server

I'm trying to migrate app to hosted parse server.App start but when it tries to query to hosted parse server it gets crashed.I had the issue with dependencies in the past now i fixed it.
If i use the parse service the app works fine.
Parse.enableLocalDatastore(this);
// Parse.initialize(this, "<key>", "<key>");
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("appid")
.clientKey("<key>")
.server("http://192.168.1.177:1337/parse/") // '/' important after 'parse'
.build());
Dependencies:
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
}
Error:
04-03 12:44:28.409 2911-2911/com.app.nameapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.app.nameapp, PID: 2911
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
Caused by: java.lang.IllegalStateException: Method requires Local Datastore. Please refer to `Parse#enableLocalDatastore(Context)`.
at com.parse.ParseQuery.throwIfLDSEnabled(ParseQuery.java:292)
at com.parse.ParseQuery.throwIfLDSDisabled(ParseQuery.java:286)
at com.parse.ParseQuery.access$200(ParseQuery.java:90) 
Could not able to post entire error message as it was very long. I think there is something wrong with parse local data store. As far as i know when pointing my app to hosted parse server i just need to add those few lines(appid,clientkey,server address). Is there any more changes needed in the app?  
  
try the following:
Parse.initialize(new Parse.Configuration.Builder(this) .applicationId("yourappid") .clientKey("yourclientkey") .server("serverurl") .enableLocalDataStore() .build() );
It seems like you are trying to initialize Parse from an onClickListener, therefore the object this you are passing to Parse is the wrong one.
if you refer to this from on OnClickListener you get a reference to the interface even though it's an inline declaration in the activity.
you need to manually point to the correct Context and use it.
try changing your code to look like this:
Parse.enableLocalDatastore(MyActivity.this);
// Parse.initialize(this, "<key>", "<key>");
Parse.initialize(new Parse.Configuration.Builder(MyActivity.this)
.applicationId("appid")
.clientKey("<key>")
.server("http://192.168.X.XXX:1337/parse/") // '/' important after 'parse'
.build());

Unmarshalling unknown type code 6881391 at offset 4752 After Upgrading to Support Libraries 23.2.0

My app has been working well at Support Libraries 23.1.1. However, after upgrading to Support Libraries 23.2.0, it starts to crash. The crash happens when I navigate from an activity back to the main activity (for example, I open the about activity from main activity's actionbar menu, then press back button to go back to main activity, then it crashes).
The crash log is here:
FATAL EXCEPTION: main Process: com.myapp.blah.blah, PID: 22124
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.myapp.blah.blah/com.myapp.blah.blah.ui.MainActivity}:
java.lang.RuntimeException: Parcel android.os.Parcel#41d10870:
Unmarshalling unknown type code 6881391 at offset 4752 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5584) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.RuntimeException: Parcel android.os.Parcel#41d10870:
Unmarshalling unknown type code 6881391 at offset 4752 at
android.os.Parcel.readValue(Parcel.java:2087) at
android.os.Parcel.readArrayMapInternal(Parcel.java:2321) at
android.os.Bundle.unparcel(Bundle.java:249) at
android.os.Bundle.getSparseParcelableArray(Bundle.java:1273) at
com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1884)
at android.app.Activity.onRestoreInstanceState(Activity.java:989) at
android.app.Activity.performRestoreInstanceState(Activity.java:961) at
android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1145)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2407)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)?
at android.app.ActivityThread.access$800(ActivityThread.java:166)? at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)?
at android.os.Handler.dispatchMessage(Handler.java:102)? at
android.os.Looper.loop(Looper.java:136)? at
android.app.ActivityThread.main(ActivityThread.java:5584)? at
java.lang.reflect.Method.invokeNative(Native Method)? at
java.lang.reflect.Method.invoke(Method.java:515)? at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)? at
dalvik.system.NativeStart.main(Native Method)?
The crash only happens if I set the developer debug option "do not keep activities" on. The crash does not happen if this option is off.
The crashes happens in debug mode where no Proguard is used.
I do not pass any parcels/bundles between the activities, and do not use startActivityForResult().
Crash happens on both pre and post Lollipop devices.
I found two similar posts here and here which might (or might not) be related.
Unmarshalling exception when using SearchView with an id resource in
appcompat 23.2
Hi, it can fix by implement onSavedInstance and onRestore but don't use super. This strange behavior
#Override
protected void onSaveInstanceState(Bundle outState) {
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
}

Invalid JSON with use Fabric SDK

I use this code and catch error:
// I I did everything according to the manual
loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Result<TwitterSession> result1 = result;
}
#Override
public void failure(TwitterException exception) {
exception.printStackTrace(); // I catch this exception
}
});
And this my logs:
01-26 12:39:10.258 32298-32298/com.DriverNotes.AndroidMobileClient E/Twitter﹕ Invalid json: <?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
at com.google.gson.JsonParser.parse(JsonParser.java:65)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
at com.twitter.sdk.android.core.TwitterApiException.parseErrorCode(TwitterApiException.java:107)
at com.twitter.sdk.android.core.TwitterApiException.readErrorCode(TwitterApiException.java:96)
at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:43)
at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:81)
at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
P.S. I hope to have given enough information about the problem
From the error, it looks like your Twitter application may need some additional information in order to work properly. Take a look at this:
https://twittercommunity.com/t/desktop-applications-only-support-the-oauth-callback-value-oob-oauth-request-token/252/2
If it's still relevant - I had the same problem and the solution was to set the redirect_url field in the app web page.
and also you MUST uncheck the textbox:
"Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url)"

Categories

Resources