我正在尝试制作可滚动选项卡,但是当我在片段布局中设置视图时,应用程序开始出现错误,显示为“Error inflating class null”。当未添加视图时,它可以工作,但是当我将视图添加到布局中时,它就会给我错误。我按照此处所述添加了类,但它不起作用。该如何解决?以下是我的片段代码:
<FrameLayout 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.neelay.anotherbeatbox.Fragment.Songs"
android:background="@color/colorPrimaryDark"
class = "com.example.neelay.anotherbeatbox.Fragment.Songs">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff"
android:layout_marginTop="150dp"/>
</FrameLayout>
片段包名是package com.example.neelay.anotherbeatbox.Fragment; 片段名称为songs。我该如何修复此错误?
E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #14: Error inflating class null
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.example.neelay.anotherbeatbox.Fragment.Songs.onCreateView(Songs.java:27)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1632)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:637)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at com.antonyt.infiniteviewpager.InfinitePagerAdapter.finishUpdate(InfinitePagerAdapter.java:67)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1237)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1085)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1611)
at android.view.View.measure(View.java:15356)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:622)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:404)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:671)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:738)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:315)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1457)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:723)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:583)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:315)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1457)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:723)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:583)
at android.view.View.measure(View.java:15356)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:315)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
at android.view.View.measure(View.java:15356)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1858)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1110)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1283)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4222)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92
D/dalvikvm: GC_CONCURRENT 释放了343K内存,剩余可用10%的空间,当前占用6423K/7111K,暂停12ms+16ms,总计53ms
我的Fragment类
package com.example.neelay.anotherbeatbox.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.neelay.anotherbeatbox.R;
public class Songs extends Fragment {
public Songs() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_songs, container, false);
}
}