首页 > 解决方案 > Android PhotoView 库错误膨胀类

问题描述

我在回收站视图中使用 PhotoView 并在适配器上膨胀视图时出错:

public PostViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = 
        LayoutInflater.from(context).inflate(R.layout._post, viewGroup, false);
    return new PostViewHolder(view);
}

这与multidex无关。所有安卓版本都出现此错误。

构建错误是:

android.view.InflateException: Binary XML file line #10 in ..:layout/_post: Binary XML file line #10 in ..4:layout/_post: Error inflating class com.github.chrisbanes.photoview.PhotoView
原因: android.view.InflateException:二进制 XML 文件第 10 行在 ...:layout/_post:错误膨胀类 com.github.chrisbanes.photoview.PhotoView
原因:java.lang.ClassNotFoundException:com.github.chrisbanes.photoview。照片视图

我的视图文件是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/row_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher"
        />
</android.support.constraint.ConstraintLayout>

和 gradle 文件:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "*****"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.1"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation('com.squareup.picasso:picasso:2.71828') {
        exclude group: 'com.android.support'
        exclude module: ['exifinterface', 'support-annotations']
    }
    implementation 'com.github.f0ris.sweetalert:library:1.5.1'
    implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '1.3.1'
    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.github.chrisbanes:PhotoView:1.2.6'
    implementation 'com.android.support:multidex:1.0.3'
}

repositories {
    mavenCentral()
}

apply plugin: 'com.google.gms.google-services'

标签: javaandroidzoomingphotoviewer

解决方案


推荐阅读