【问题标题】:android.view.InflateException: Binary XML file line #1: Error inflating class ViewPagerandroid.view.InflateException: Binary XML file line #1: Error inflating class ViewPager
【发布时间】:2015-12-13 15:43:35
【问题描述】:

这是我的代码,我尝试在容器活动中滑动屏幕,完整代码是here

Container.groovy

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.container)
    ViewPager pager = (ViewPager) findViewById(R.id.pager)
    pager.setAdapter(new PagerAdapter(fragmentManager))
}

容器.xml

<android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"/>

错误:

Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class ViewPager
           ...
            at ro.vst.Container.onCreate(Container.groovy:17)

【问题讨论】:

  • 尝试将这一行 ViewPager pager = findViewById(R.id.pager) 更改为 ViewPager pager = (ViewPager) findViewById(R.id.pager)
  • 请发布整个堆栈跟踪。

标签: android xml view


【解决方案1】:

我看了你在github上发布的代码,你的container.xml有以下内容:

<ViewPager
    android:id="@+id/pager"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"/> 

根应该是&lt;android.support.v4.view.ViewPager 而不是&lt;ViewPager,因为ViewPager 仅作为支持库的一部分退出

【讨论】:

    猜你喜欢
    • 2015-04-14
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2020-06-27
    • 1970-01-01
    • 2015-08-21
    相关资源
    最近更新 更多