Java 在片段类内膨胀异常
我正在做一个需要片段的项目。每当我在片段类中测试运行项目时,我都会得到一个指向oncreateview方法的充气线的异常,如下所示Java 在片段类内膨胀异常,java,android,android-fragments,inflate-exception,binary-xml,Java,Android,Android Fragments,Inflate Exception,Binary Xml,我正在做一个需要片段的项目。每当我在片段类中测试运行项目时,我都会得到一个指向oncreateview方法的充气线的异常,如下所示 Process: com.example.joey.maranathahealthblog, PID: 29380 android.view.InflateException: Binary XML file line #12: Error inflating class <unknown> at android.view.LayoutI
Process: com.example.joey.maranathahealthblog, PID: 29380
android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.example.joey.maranathahealthblog.BlogTabs.TabsFragments.HygieneClone.onCreateView(HygieneClone.java:27)
我的布局文件如下所示:
<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.example.joey.maranathahealthblog.BlogTabs.TabsFragments.HygieneClone">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/hygiene_recyclerView"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/newPost_Fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_add_black_24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginBottom="40dp"/>
由于此异常,应用程序甚至没有加载第一个屏幕,这可能是什么原因造成的 因为您没有与android.support.design.widget.FloatingActionButton相关的依赖项。 尝试添加-- 编译'com.android.support:design:23.2.0'
在build.gradleshow
fragment\u-clone
xml中,您是否已经在ur-gradlew中编译了“com.android.support:design:X.X.X”?@ρ∑ѕρєK,这是上面显示的布局文件。我将从xml文件中删除每个控件,看看程序在没有它的情况下是否运行良好。若好,那个么问题将直接转到该控件。如果删除所有控件后保持不变,则代码必须包含错误,而不是xml文件。我添加了依赖项,但问题仍然存在。1.按Ctrl键并单击xml文件中的android.support.design.widget.FloatingActionButton,是否可以跳到FloatingActionButton.java文件?2.尝试清理项目?我已尝试清理项目并再次运行应用程序。显示相同的错误。是否也有NoSuchMethodError错误?请参见:
<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.example.joey.maranathahealthblog.BlogTabs.TabsFragments.HygieneClone">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/hygiene_recyclerView"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/newPost_Fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_add_black_24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginBottom="40dp"/>