二进制 XML 文件第 18 行:膨胀 class android.support.v4.widget.view.ViewPager 时出错

Binary XML file line #18: Error inflating class android.support.v4.widget.view.ViewPager

你好,我想在 android studio 中创建一个选项卡布局和视图寻呼机 这是我的 activity_xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

  <android.support.design.widget.TabLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/colorPrimary"
      app:tabGravity="fill"
      app:tabMode="fixed"
      app:tabIndicatorColor="@color/colorAccent"
      android:id="@+id/tablayout_id"></android.support.design.widget.TabLayout>
    <android.support.v4.widget.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/viewPager_id">
    </android.support.v4.widget.view.ViewPager>
</LinearLayout>

这是我的 MainActivity:

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ViewPagerAdapter viewPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tabLayout = (TabLayout) findViewById(R.id.tablayout_id);
        viewPager = (ViewPager) findViewById(R.id.viewPager_id);
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());

        viewPagerAdapter.AddFragment(new FragmentCall(),"Call"); // `new FragmentCall()` should be inside `FragmentPagerAdapter.getItem()`
        viewPagerAdapter.AddFragment(new FragmentContact(), "Contact"); // `new FragmentContact()` should be inside `FragmentPagerAdapter.getItem()`
        viewPagerAdapter.AddFragment(new FragmentFav(), "Fav"); // `new FragmentFav()` should be inside `FragmentPagerAdapter.getItem()`

        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}

错误说:二进制 XML 文件行 #18:二进制 XML 文件行 #18:错误膨胀 class android.support.v4.widget.view.ViewPager 并且:没有找到 class "android.support.v4.widget.view.ViewPager 我曾经在 link 中搜索此错误:Error inflating class android.support.v4.view.ViewPager,但我不明白如何解决该错误,他说右键单击 jar,然后 select Build Path 和单击添加到构建路径。而且我不明白如何 select 构建路径。

替换

android.support.v4.widget.view.ViewPager

android.support.v4.view.ViewPager