当前位置:   article > 正文

安卓开发——Error inflating class ******(com.example.pull_to_refresh.PullToRefreshView)

error inflating class

Error inflating class ******(com.example.pull_to_refresh.PullToRefreshView)
肝了一天,问题解决之后气炸了,小白的老师布置了一个实验,其中有一个项目模板,老师要求先把模板运行起来,当小白更改完版本以及依赖配置问题之后后,便开始运行项目,结果模拟器上显示要么只显示白屏,要么显示应用已停止运行。当小白进行代码检查时,确实没有发现问题。当与bug抗争了一天之后,小白灵机一动,会不会是路径的问题,果然
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
如上图所示,在xml文件中引用了一个自定义类PullToRefreshView,而小白犯的错误就是没有对应好路径(上图已改正),所以如果大家在运行项目时,发现类似问题,要仔细考虑一下路径有无错误。

虽然小白没有出现版本问题,但还是觉得有必要贴一下代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30"

    defaultConfig {
        applicationId "com.example.food3"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
//    compile 'com.android.support:appcompat-v7:+'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    compile 'com.yalantis:phoenix:1.2.3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

注:模拟器上出现应用已停止运行类似的问题解决常见错误
1.xml文件中代码有误,可能是元素的layout_width和layout_height未设置,也可能是xml中引用的资源不存在或者资源的路径不对
2.java代码有误,出现这种问题时,小白一般都是从上到下逐步对代码进行抛异常。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/235486
推荐阅读
相关标签
  

闽ICP备14008679号