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.xml文件中代码有误,可能是元素的layout_width和layout_height未设置,也可能是xml中引用的资源不存在或者资源的路径不对
2.java代码有误,出现这种问题时,小白一般都是从上到下逐步对代码进行抛异常。