【问题标题】:Error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView膨胀类 edmt.dev.video player.VideoPlayer RecyclerView 时出错
【发布时间】:2022-02-04 18:44:45
【问题描述】:

我正在尝试包含 edmt.dev.videoplayer.VideoPlayerRecyclerView 以在我的 Android 应用中显示多个视频。构建没有错误。但是膨胀类 edmt.dev.videoplayer.VideoPlayerRecyclerView 时出错。无法检测到我做错了什么。提前感谢您的帮助。

错误日志:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gogon.wetest, PID: 15582
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView
    Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.gogon.wetest.ui.watch.WatchFragment.onCreateView(WatchFragment.java:38)

fragment_watch.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/success_green"
    tools:context="com.gogon.wetest.ui.watch.WatchFragment">

    <edmt.dev.videoplayer.VideoPlayerRecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/video_player_id"
        android:orientation="vertical"/>
</RelativeLayout>

WatchFragment.java

package com.gogon.wetest.ui.watch;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.gogon.wetest.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import butterknife.BindView;
import butterknife.ButterKnife;
import edmt.dev.videoplayer.VideoPlayerRecyclerView;
import edmt.dev.videoplayer.adapter.VideoPlayerRecyclerAdapter;
import edmt.dev.videoplayer.model.MediaObject;
import edmt.dev.videoplayer.utils.VerticalSpacingItemDecorator;

public class WatchFragment extends Fragment {

    VideoPlayerRecyclerView videoPlayerRecyclerView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fragment_watch, container, false);

        videoPlayerRecyclerView = view.findViewById(R.id.video_player_id);

        ButterKnife.bind(requireActivity());
        init();

        return view;
    }

    private void init() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        videoPlayerRecyclerView.setLayoutManager(layoutManager);
        VerticalSpacingItemDecorator verticalSpacingItemDecorator = new VerticalSpacingItemDecorator(10);
        videoPlayerRecyclerView.addItemDecoration(verticalSpacingItemDecorator);

        ArrayList<MediaObject> sourceVideos = new ArrayList<>(sampleVideoList());
        videoPlayerRecyclerView.setMediaObjects(sourceVideos);

        VideoPlayerRecyclerAdapter videoAdapter = new VideoPlayerRecyclerAdapter(sourceVideos, initGlide());
        videoPlayerRecyclerView.setAdapter(videoAdapter);
    }

    private RequestManager initGlide() {

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.drawable.white_background)
                .error(R.drawable.white_background);

        return Glide.with(getContext()).setDefaultRequestOptions(requestOptions);
    }

    private List<MediaObject> sampleVideoList() {

        return Arrays.asList(
                //title, media-url, thumbnail, description
                new MediaObject(
                        "For Bigger Blazes",
                        "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
                        "https://i.ytimg.com/vi/Dr9C2oswZfA/maxresdefault.jpg",
                        "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
                ),
                new MediaObject(
                        "Tears of Steel",
                        "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
                        "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTSNuOK0PKeBYclnOvqAmKtUlJ_nQsN0YPYZ8gL7u-wKilHYs2S",
                        "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
                ),
                new MediaObject(
                        "What care can you get for a grand?",
                        "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WhatCarCanYouGetForAGrand.mp4",
                        "https://www.jeep.com/content/dam/fca-brands/na/jeep/en_us/2021/grand-cherokee/gallery/exterior/MY21-Grand-Cherokee-Gallery-Exterior-Overland-Granite-Crystal-Desktop.jpg.image.1440.jpg",
                        "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
                )
        );
    }
}

build.gradle:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'androidx.navigation.safeargs'
}

repositories {
    google() 
    mavenCentral()
}


android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.gogon.wetest"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 5
        versionName "1.0.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    //enable view binding
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    //for video player
    implementation "com.google.android.exoplayer:exoplayer:2.16.1"
    implementation 'com.jakewharton:butterknife:10.2.3'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
    implementation 'com.github.eddydn:videoplayer:1.10'
    
    //glide- for image loading and caching library
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}

【问题讨论】:

    标签: java android android-recyclerview android-videoview


    【解决方案1】:

    我找到了原因,这是你项目中VideoPlayerRecyclerView类的目录,edmt.dev.videoplayer前缀是你复制的源代码的包名,replce你的包目录,(代码中VideoPlayerRecyclerView类的目录)

    对你来说是 com.gogon.wetest.VideoPlayerRecyclerView ,检查 VideoPlayerRecyclerView 类的正确目录地址

    【讨论】:

    • 是的,我已经使用这个 implementation 'com.github.eddydn:videoplayer:1.10' 包含了 edmt.dev.videoplayer.VideoPlayerRecyclerView 的依赖项,我认为这个依赖库现在是私有的/移动的/隐藏的,所以它不起作用。
    • 你为什么不使用 Exomedia 库!?
    • 稍后我会为您检查图书馆
    • 现在决定使用 Exomedia 库。谢谢。
    • 我已经更新了我的答案,请看; 0 我找到了原因, 这是你项目中 VideoPlayerRecyclerView 类的目录,edmt.dev.videoplayer 前缀是你复制它的源代码的包名,replce你的包目录,(代码中 VideoPlayerRecyclerView 类的目录)
    猜你喜欢
    • 2015-04-13
    • 2017-03-06
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2017-02-28
    相关资源
    最近更新 更多