我正在尝试创建一个可滚动的选项卡但是当我在我的片段布局中设置一个视图时,应用程序开始给出错误,因为错误膨胀类为null。当没有添加视图但是当我在布局中添加视图时它正在工作给我错误。 我也把这个类添加到给定的here但它没有用。我可以解决这个问题,这是我的片段代码
<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>
片段包名称是包com.example.neelay.anotherbeatbox.Fragment; 片段名称歌曲。我可以解决这个问题吗? 错误
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
我的片段类
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);
}
}
答案 0 :(得分:20)
替换
<view
与
<View
View
是一个实际的小部件,您可以充气并且似乎符合您的预期目的。 view
是一个特殊标记,使用它可以通过属性中定义的名称来扩展视图类,并且您没有定义这样的类名(在inflater中它出现为null
)。
答案 1 :(得分:0)
您需要为视图类定义正确的包名称。通过查看类中定义的包名称,您可以在布局xml中定义它,如此
<com.example.neelay.anotherbeatbox.Fragment.Songs
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff"
android:layout_marginTop="150dp"/>