我已经检查了所有类似的问题(这个和其他),但仍然无法找出错误的原因,它在运行时的某个时候一直关闭。。。
ragment.java
/**
* A simple {@link Fragment} subclass.
*/
public class CategoryDetailFragment extends Fragment implements View.OnClickListener{
@BindView(R.id.categoryNameTextView) TextView mCategoryNameTextView;
@BindView(R.id.addPostButton) Button mAddPostButton;
private Category mCategory;
public static CategoryDetailFragment newInstance(Category category) {
CategoryDetailFragment categoryDetailFragment = new CategoryDetailFragment();
Bundle args = new Bundle();
args.putParcelable("category", Parcels.wrap(category));
categoryDetailFragment.setArguments(args);
return categoryDetailFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCategory = Parcels.unwrap(getArguments().getParcelable("category"));
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_category_detail, container, false);
ButterKnife.bind(this, view);
mAddPostButton.setOnClickListener(this);
mCategoryNameTextView.setText(mCategory.getName());
return view;
}
fragment\u category\u详细信息。xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.epicodus.talkaboutit.ui.CategoryDetailFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Category Name"
android:id="@+id/categoryNameTextView"
android:layout_gravity="center"
android:textAlignment="center"
android:paddingTop="10dp"
android:textSize="20sp"/>
<fragment
android:name = "com.epicodus.talkaboutit.ui.PostListFragment"
android:id="@+id/postListFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_post_list"
android:layout_below="@+id/categoryNameTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="69dp"
android:layout_above="@+id/addPostButton" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Post"
android:id="@+id/addPostButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
错误:
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.epicodus.talkaboutit, PID: 27394
android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at com.epicodus.talkaboutit.ui.CategoryDetailFragment.onCreateView(CategoryDetailFragment.java:57)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:20151)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3158)
at android.view.View.measure(View.java:20151)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2594)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1549)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1841)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.interna
I/Process: Sending signal. PID: 27394 SIG: 9
Application terminated.
错误似乎来自这一行
View view = inflater.inflate(R.layout.fragment_category_detail, container, false);
我已经尽力了,非常感谢您的帮助。。。
它正在崩溃,因为它无法使用类找到片段,您应该像下面这样提及片段名称
把这个换了
<fragment
class = "com.epicodus.talkaboutit.ui.PostListFragment"
android:id="@+id/postListFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_post_list"
android:layout_below="@+id/categoryNameTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="69dp"
android:layout_above="@+id/addPostButton" />
到这个
<fragment
android:name = "com.epicodus.talkaboutit.ui.PostListFragment"
android:id="@+id/postListFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_post_list"
android:layout_below="@+id/categoryNameTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="69dp"
android:layout_above="@+id/addPostButton" />
检查是否将片段的布局文件保存为V-24。如果您的最低SDK版本低于24,这可能会导致视图膨胀问题。据我所知,android中的视图膨胀错误主要是由于版本特定的布局或可绘制。
我正在尝试遵循Maps API指南,但我已经出现此错误一段时间了。我已经尝试过: android.view.InflateException:二进制XML文件:inflating类片段错误 这是我的xml代码 这是我的主要活动
我无法解决这个问题。这里我有3个选项卡,它们是使用创建的,前两个选项卡包含一般列表,第三个是GoogleMap。它在第一次正确加载,在这里,如果我导航回第一个选项卡并返回第二个或第三个选项卡,应用程序会通过说 我已经在Gist中添加了代码,请检查以下链接应用程序代码
当我试图为我的一个android应用程序使用GoogleMapAPI时,我总是看到这个错误。我发现许多类似的问题,但没有一个答案适合我。 这是我看到的错误: 块报价08-06 19:31:47.606 2602-2602/com。实例安克。mymap E/AndroidRuntime:致命异常:主进程:com。实例安克。mymap,PID:2602 java。lang.RuntimeExcepti
我想在tablet视图中显示列表+描述。下面的代码在纵向模式下运行良好,但在横向模式下停止运行。有什么不对劲吗? 主要活动 布局/ActivityMain.xml res/layout-land/activitymain.xml LayoutDetailFragment.xml 错误 E/AndroidRuntime:致命异常:主进程:com.example.fyp_awais.tab,PID:3
我有两天的时间研究这个问题,并尝试了所有的解决方案,但没有任何效果。以下是我的代码: LogCat: 以下是我的主要活动。Java语言 程序包com。我mystatus; 活动_Main。xml 显示xml: 请帮忙。
这里的主要问题是:上面的代码在几乎所有的设备(受刺激的设备,或者一些真实的设备)上都能顺利运行。但当我在三星S3上运行时。它注意到这个错误: 请告诉我如何修复错误,谢谢:)