java.lang.IllegalStateException Fragment not attached to Activity
<p>After I receive a response with Volley, I have to get back to the main fragment.
I have two different volley requests , depending on some condition, I'll call it 'a' in this example.
The weird thing is the when <strong>a==1, popBackStack gets me successfully</strong> to the main fragment .
<strong>When a==0 it crashes</strong> and I receive  <code>java.lang.IllegalStateException Fragment not attached to Activity</code>
I tried creating a new main fragment (transaction.commit....) but it didn't help. </p>

<pre><code>if( a == 0 )
{
    VolleyManager.add(jsnObj,
        new RequestListener() {

                    @Override
                    public &lt;T&gt; void onSuccess(T object) {
                        mFragmentManager.popBackStack(DataManager.BACK_STACK_KEY_MAIN_FRAGMENT, 0);
                    }
                    });
                }
else if( a==1 )
{
    VolleyManager.update(jsnObj,
        new RequestListener() {

                @Override
                public &lt;T&gt; void onSuccess(T object) {
                        mFragmentManager.popBackStack(DataManager.BACK_STACK_KEY_MAIN_FRAGMENT, 0);
                }   
                });
    }
</code></pre>

<p>Error - </p>

<pre><code>  java.lang.IllegalStateException: Fragment MainFragment{6aaaf7f} not attached to Activity
  at android.app.Fragment.getResources(Fragment.java
</code></pre>

<p>The problem seems to be with the <code>getResources()</code>, but I do the same thing when a==1 and I've got no problems at all. </p>