二进制 XML 文件行 #52:二进制 XML 文件行 #52:膨胀 class com.askira.loopingviewpager.LoopingViewPager 时出错

Binary XML file line #52: Binary XML file line #52: Error inflating class com.askira.loopingviewpager.LoopingViewPager

我正在尝试使用 askira.loopingViewPager 设置菜单。但是,当我 运行 应用程序崩溃时,因为它无法从登录 activity 转到 HomeActivity;显示我在下面粘贴的错误...我想我的 XML 文件中可能还有一些来自我的旧布局的元素,但我找不到一些?! 我仍然认为问题出在 XML 文件中。我能做些什么来解决这个问题? 代码编译正常,没有错误,Gradle 已更新到最新版本。 如果您需要更多信息,请告诉我。谢谢。

Process: com.example.login, PID: 24891
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.login/com.example.login.HomeActivity}: android.view.InflateException: Binary XML file line #52: Binary XML file line #52: Error inflating class com.askira.loopingviewpager.LoopingViewPager
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
        at android.app.ActivityThread.access0(ActivityThread.java:154)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:234)
        at android.app.ActivityThread.main(ActivityThread.java:5526)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.view.InflateException: Binary XML file line #52: Binary XML file line #52: Error inflating class com.askira.loopingviewpager.LoopingViewPager
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.example.login.ui.home.HomeFragment.onCreateView(HomeFragment.java:42)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2646)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2416)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2372)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
        at android.app.Activity.performStart(Activity.java:6302)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2427)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524) 
        at android.app.ActivityThread.access0(ActivityThread.java:154) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:234) 
        at android.app.ActivityThread.main(ActivityThread.java:5526) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class com.askira.loopingviewpager.LoopingViewPager
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at com.example.login.ui.home.HomeFragment.onCreateView(HomeFragment.java:42) 
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439) 
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) 
        at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2646) 
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2416) 
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2372) 
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) 
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466) 
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483) 
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) 
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) 
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) 
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620) 
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238) 
        at android.app.Activity.performStart(Activity.java:6302) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2427) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524) 
        at android.app.ActivityThread.access0(ActivityThread.java:154) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:234) 
        at android.app.ActivityThread.main(ActivityThread.java:5526) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.askira.loopingviewpager.LoopingViewPager" on path: DexPathList[[zip file "/data/app/com.exampl

XML-首页片段

<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@android:color/white"
        android:weightSum="5">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical"
        android:background="@android:color/white"
        android:padding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="@string/popular_categories"
            android:textSize="24sp"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_popular"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:orientation="vertical"
        android:background="@android:color/white"
        android:padding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="@string/best_deals"
            android:textSize="24sp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="8dp"/>

        <com.askira.loopingviewpager.LoopingViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:isInfinite="true"
            app:autoScroll="true"
            app:scrollInterval="5000"
            app:viewpagerAspectRatio="1.33"/>
    </LinearLayout>
    </LinearLayout>

</RelativeLayout>

主页片段

public class HomeFragment extends Fragment {

    private HomeViewModel homeViewModel;

    Unbinder unbinder;

    @BindView(R.id.recycler_popular)
    RecyclerView recycler_popular;
    @BindView(R.id.viewpager)
    LoopingViewPager viewPager;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel = ViewModelProviders.of(this).get(HomeViewModel.class);
        View root =inflater.inflate(R.layout.fragment_home,container,false);
        unbinder= ButterKnife.bind(this,root);
        init();
        homeViewModel.getPopularList().observe(this,popularCategoryModels ->{
            //Create Adapter
            MyPopularCategoriesAdapter adapter=new MyPopularCategoriesAdapter(getContext(),popularCategoryModels);
            recycler_popular.setAdapter(adapter);
        });

        homeViewModel.getBestDealList().observe(this,bestDealModels -> {
            MyBestDealsAdapter adapter = new MyBestDealsAdapter(getContext(),bestDealModels,true);
            viewPager.setAdapter(adapter);
        });
        return root;
    }

    private void init() {
        recycler_popular.setHasFixedSize(true);
        recycler_popular.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false));

    }
    @Override
    public void onResume(){
        super.onResume();
        viewPager.resumeAutoScroll();
    }
    @Override
    public void onPause(){
        viewPager.pauseAutoScroll();
        super.onPause();

    }

部分GradleAPP

implementation 'com.asksira.android:loopingviewpager:1.1.4'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

您拼错了包名:它是 com.asksira,而不是 com.askira - 您漏掉了 s.

<com.asksira.loopingviewpager.LoopingViewPager
        android:id="@+id/viewpager"

public class HomeFragment extends Fragment {

    private HomeViewModel homeViewModel;
    Unbinder unbinder;

    @BindView(R.id.recycler_popular)
    RecyclerView recycler_popular;


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState){

        homeViewModel =
                ViewModelProviders.of(this).get(HomeViewModel.class);
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        unbinder = ButterKnife.bind(this, root);
        init();

// under the HomeFragment I change the "this" INTO "getActivity" as seen below 

        homeViewModel.getPopularList().observe(getActivity(), popularCategoryModels -> {
            // Creating the Adapter
            MyPopularCategoriesAdapter adapter = new MyPopularCategoriesAdapter(getContext(),
                    popularCategoryModels);
            recycler_popular.setAdapter(adapter);

        });
        return  root;
    }

    private void init() {
        recycler_popular.setHasFixedSize(true);
        recycler_popular.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));

    }

}