6

I get IllegalStateException on Google-Play Console which I can not reproduce and I don't understand what is the issue.

Here is the log from Google-Play Console

java.lang.RuntimeException: 
    at com.loopj.android.http.AsyncHttpResponseHandler.onUserException (AsyncHttpResponseHandler.java:304)
    at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:395)
    at com.loopj.android.http.AsyncHttpResponseHandler$ResponderHandler.handleMessage (AsyncHttpResponseHandler.java:510)
    at android.os.Handler.dispatchMessage (Handler.java:102)
    at android.os.Looper.loop (Looper.java:148)
    at android.app.ActivityThread.main (ActivityThread.java:5441)
    at java.lang.reflect.Method.invoke (Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:738)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:628)

Caused by: java.lang.IllegalStateException: 
    at android.support.v4.app.FragmentManagerImpl.enqueueAction (FragmentManager.java:1515)
    at android.support.v4.app.BackStackRecord.commitInternal (BackStackRecord.java:638)
    at android.support.v4.app.BackStackRecord.commit (BackStackRecord.java:617)
    at android.support.v4.app.DialogFragment.show (DialogFragment.java:139)
    at com.example.eliran.forum.ForumFragment.regularTopic (ForumFragment.java:240)
    at com.example.eliran.forum.ForumFragment.enterTopic (ForumFragment.java:225)
    at com.example.eliran.forum.ForumFragment$13.onSuccess (ForumFragment.java:620)
    at com.loopj.android.http.TextHttpResponseHandler.onSuccess (TextHttpResponseHandler.java:118)
    at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:351)

According to the logs that I've attached, the flow is like this:

  1. The fragment created and calls to function which uses AsyncHttpClient.
  2. AsyncHttpClient done with success result which return json object.
  3. AsyncHttpClient success calls to enterTopic with the json.
  4. enterTopic calls to regularTopic.
  5. In this function (regularTopic) it happens. Here is the function:

    public void regularTopic(ForumTopic forumTopic, int positionInArray) {
        FragmentManager fm = getChildFragmentManager();
        ForumTopicDialogFragment dialogFragment = new 
        ForumTopicDialogFragment();
        dialogFragment.setTargetFragment(this,100);
        Bundle bundle = new Bundle();
        bundle.putInt("posInArray", positionInArray);
        bundle.putSerializable("topic", forumTopic);
        dialogFragment.setArguments(bundle);
        dialogFragment.show(fm, ""); }
    

Here is the AsyncHttpClient request (onSuccess should run from the UIThread):

AsyncHttpClient client = new AsyncHttpClient();
String url = TheFinals.HOST + "/topics/" + id;
client.get(url, new TextHttpResponseHandler() {
    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, String responseString) {
        try {
            JSONArray topic = new JSONArray(responseString);
            if (topic.length() > 0) {
                JSONObject jsonObject = topic.getJSONObject(0);
                ForumTopic forumTopic = new ForumTopic(jsonObject.getInt("id"), jsonObject.getInt("userid"),
                        jsonObject.getString("content"), jsonObject.getString("title"), jsonObject.getString("firstname"),
                        jsonObject.getString("time"), jsonObject.getInt("icon"), jsonObject.getString("fbid")
                        , jsonObject.getInt("status"), jsonObject.getInt("anonymous"), jsonObject.getInt("catid"), jsonObject.getString("picture"));
                ForumFragment.this.enterTopic(forumTopic, -1);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

});

Can someone help please? First I need to reproduce this issue in my phone :\

4
  • Are you calling regularTopic on the main thread? could you post the code when you call to regularTopic? Commented Nov 19, 2017 at 23:06
  • @diegoveloper I edited my post - attached the code. enterTopic called from onSuccess after the asynctask ends. Commented Nov 19, 2017 at 23:24
  • could you reproduce the issue? Commented Nov 19, 2017 at 23:25
  • @diegoveloper no, I wish Commented Nov 19, 2017 at 23:26

2 Answers 2

11

This issue is related to this bug. I solved it by override the show method in my dialog fragment:

@Override
public void show(FragmentManager manager, String tag) {
    try {
        FragmentTransaction ft = manager.beginTransaction();
        ft.add(this, tag).addToBackStack(null);
        ft.commitAllowingStateLoss();
    } catch (IllegalStateException e) {
        Log.e("IllegalStateException", "Exception", e);
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

But with this solution(commitAllowingStateLoss), if we're passing something to that fragment, we will lose it, if IllegalStateException occurs.
0

Try calling enterTopic after 500ms delay:

//declare this as global variable on your activity
final Handler handler = new Handler();


handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    ForumFragment.this.enterTopic(forumTopic, -1);
  }
}, 500);

9 Comments

do you have any clue how to reproduce this issue before Ill try to fix it?
I had a similar issue but only happens in some devices :/
Caused by: java.lang.IllegalStateException:
Yes, I mean the specific issue.Do you think ForumFragment.this isnt created yet?
Probably, it's very weird because as I said it only happens in some devices and Android OS versions
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.