Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException when trying to show dialog fragment

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 :\

like image 268
Eliran Tutia Avatar asked Nov 19 '17 23:11

Eliran Tutia


1 Answers

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);
    }

}
like image 88
Eliran Tutia Avatar answered Nov 04 '22 13:11

Eliran Tutia