我正在
java.lang.IllegalArgumentException:
在cameraIntent启动后从onActivityResult
检索数据时。我正在使用嵌套片段。
这就是场景。 MainActivity.class
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
我在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;
}
}
在ParentFragment中,我正在给正在调用cameraIntent的ChildFragment充气。
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;
}
}
我已在AndroidManifest中声明该活动仅处于纵向模式。
我得到这个java.lang.IllegalArgumentException:随机且只在某些三星设备上。我注意到,当您在某些三星设备上打开相机时,相机处于横向状态,相机关闭后不久(保存照片)应用程序处于横向模式,并且它会快速旋转到在AndroidManifest中声明的纵向。 此错误完全随机发生。有时在拍摄5-6张图像后,有时会拍摄第一张图像。
这是我的完整logcat错误。
: 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
答案 0 :(得分:-2)
您的MainActivity
应该延伸FragmentActivity
,而不仅仅是Activity
如下所示,
public class MainActivity extends FragmentActivity // Change here
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}