gpt4 book ai didi

未显示 Android Studio 预览

转载 作者:行者123 更新时间:2023-12-01 09:34:24 34 4
gpt4 key购买 nike

The following classes could not be instantiated: androidx.fragment.app.FragmentContainerView (Open Class, Show Exception, Clear Cache)

Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.

Exception Details:

java.lang.UnsupportedOperationException: FragmentContainerView must be within a FragmentActivity to be instantiated from XML. 
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:117)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1123)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)


显示此消息并且布局预览未显示在基本 Activity 或其他模板接受空 Activity 中。

在此消息之前,显示了一条关于将 fragment 标记替换为 fragmentcontainerview 的消息.我解决了这个问题,然后显示了上述消息。我已经尝试过已知的解决方案,如重建、刷新布局和无效缓存/重新启动等,但他们没有成功。

最佳答案

如果您查看 FragmentContainerView 的源代码,你会看到:

/**
* Do not call this constructor directly. Doing so will result in an
* {@link UnsupportedOperationException}.
*/
public FragmentContainerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
throw new UnsupportedOperationException("FragmentContainerView must be within a "
+ "FragmentActivity to be instantiated from XML.");
}

不幸的是,这是布局预览调用的构造函数。在 Android Studio 团队修复此问题之前,您似乎无能为力。

这是系统“应该”使用的构造函数:
FragmentContainerView(Context context, AttributeSet attrs, FragmentManager fm) {
// ...
}

如果您实际运行您的应用程序,应该调用它并且一切都应该正常工作。

关于未显示 Android Studio 预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60674505/

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