gpt4 book ai didi

android - java.lang.IllegalArgumentException : No view found for id 异常

转载 作者:太空狗 更新时间:2023-10-29 15:28:20 26 4
gpt4 key购买 nike

我得到了

java.lang.IllegalArgumentException:

在 cameraIntent 启动后从 onActivityResult 检索数据时。我正在处理嵌套 fragment 。

场景是这样的。MainActivity.类

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

setContentView(R.layout.activity_main);
}
}

我在 MainActivity 中膨胀的父 fragment

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 中声明该 Activity 将仅处于纵向模式。

我收到此 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

最佳答案

您的 MainActivity 应该扩展 FragmentActivity 而不仅仅是 Activity

像下面一样,

public class MainActivity extends FragmentActivity            // Change here
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

关于android - java.lang.IllegalArgumentException : No view found for id 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21622649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com