3

I am getting

java.lang.IllegalArgumentException:

when retrieving data from onActivityResult after cameraIntent is started. I am working with nested fragments.

This is the scenario. MainActivity.class

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
}
}

The parent fragment that I am inflating in MainActivity

ParentFragment.class

public class ParentFragment extends Fragment  {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.parent_fragment, null);

        return v;
    }
}

And in the ParentFragment I am inflating the ChildFragment which is calling the cameraIntent.

ChildFragment.class

public class ChildFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.child_fragment, container,
                false);

        return v;
    }
}

I have declared in AndroidManifest that the activity will only be in Portrait mode.

I am getting this java.lang.IllegalArgumentException: randomly and only on some Samsung devices. I noticed that when you are opening the camera on some of the Samsung devices the camera is in Landscape, and shortly after the camera is closed (Save Photo) the application is in Landscape mode and it's quickly rotating to Portrait which is declared in AndroidManifest. This error is happening totally random. Sometimes after 5-6 images captured, sometimes on the first one.

Here is my full logcat error.

: java.lang.IllegalArgumentException: No view found for id 0x7f0600da (com.example.app:id/parent_fragment_bottom_container) for fragment ChildFragment
{41d21e50 #23 id=0x7f0600da}
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3512)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread.access$700(ActivityThread.java:130)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.os.Looper.loop(Looper.java:137)
01-30 16:14:14.855: E/AndroidRuntime(16047): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-30 16:14:14.855: E/AndroidRuntime(16047): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 16:14:14.855: E/AndroidRuntime(16047): at java.lang.reflect.Method.invoke(Method.java:511)
01-30 16:14:14.855: E/AndroidRuntime(16047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-30 16:14:14.855: E/AndroidRuntime(16047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-30 16:14:14.855: E/AndroidRuntime(16047): at dalvik.system.NativeStart.main(Native Method)
01-30 16:14:14.855: E/AndroidRuntime(16047): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0600da (com.example.app:id/parent_fragment_bottom_container) for fragment ChildFragment{41d21e50 #23 id=0x7f0600da
Naskov
  • 4,121
  • 5
  • 38
  • 62
  • My guess is the parent fragment is being destroyed and not being reattached to your activity. This could be because your activity was paused, or due to a screen orientation change. Try moving your Super.OnCreate to after you set contentview, because if the activity is destroyed and being recreated, you are overwriting the view holding the saved fragments with a new view. I'd also put some log messages in all the activity / fragment onCreateView and on Destroys so you can see what is happening. – NameSpace Feb 07 '14 at 08:34
  • @user3126670 I did placed Log messages in onCreateView, onCreate, onPause, onResume and etc. Sometimes when I click on the "fire cameraIntent button" the onPause is not called that the exception is thrown.. The thing that bugs me it that it is happening totally random. Any suggestions? – Naskov Feb 07 '14 at 09:13
  • You mention the error is happening when the camera is closed. Perhaps "on pause" is being skipped, straight for onDestroy ...i believe that can happen. Make the log in the onCreate your first line, and see if onCreate is even being called when the camera closes. If it is, then it's a problem with your activity recreating itself. – NameSpace Feb 07 '14 at 09:21
  • Did anyone ever solve this? I have the same issue – Mike Baglio Jr. Dec 22 '15 at 15:32
  • @MikeBaglioJr. yes, here is the answer. http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit/28845153#28845153 – Naskov Dec 23 '15 at 03:35

1 Answers1

-2

Your MainActivity should extends FragmentActivity rather than just Activity

Like below,

public class MainActivity extends FragmentActivity            // Change here
{
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
user3264399
  • 284
  • 1
  • 13
  • Negative, that is not the solution, this error is happening totally random and only on Samsung Devices. FragmentActivity wont solve this. – Naskov Feb 07 '14 at 08:34
  • 1
    That's only true if android.support.v4.app.Fragment is being used, and I can't tell that it is. Pretty sure it wouldn't even compile if that was the case. – NameSpace Feb 07 '14 at 08:34
  • Yes, I am using android.support.v4.app.Fragment, but that is not the problem, there is something to do with the Fragment LifeCycle. Cause sometimes when I am starting the CameraIntent the Fragment and the Activity are not entering in onPause. – Naskov Feb 07 '14 at 08:39
  • well guess i retract then, it does compile... Not sure if using the normal fragment manager with a support fragment is kosher or not. – NameSpace Feb 07 '14 at 08:47
  • @user3126670 I tried using both, the normal fragment and the support one, still getting the same error.. – Naskov Feb 07 '14 at 09:45
  • This is wrong answer....you should check yourself before giving any answer – Shubhamhackz Dec 01 '17 at 10:14