我正在为Place Picker创建一个演示项目。但是,当我单击按钮选择位置时,它给了我AppCompatViewInflater ClassNotFoundException异常,并且Google地图立即关闭。
这是我的logcat错误-
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatViewInflater" on path: DexPathList[[zip file "/system/framework/com.android.location.provider.jar", zip file "/system/framework/com.android.media.remotedisplay.jar", zip file "/data/app/com.google.android.gms-2/base.apk"],nativeLibraryDirectories=[/data/app/com.google.android.gms-2/lib/arm64, /data/app/com.google.android.gms-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.lang.Class.forName(Class.java:285)
at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):1)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(:com.google.android.gms@14366020@14.3.66 (040406-213742215):1)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
android.support.v7.app.AppCompatDelegateImpl.o(:com.google.android.gms@14366020@14.3.66 (040406-213742215):8)
at android.support.v7.app.AppCompatDelegateImpl.b(:com.google.android.gms@14366020@14.3.66 (040406-213742215):56)
at dlf.setContentView(:com.google.android.gms@14366020@14.3.66 (040406-213742215):1)
at com.google.android.places.ui.placepicker.PlacePickerChimeraActivity.onCreate(:com.google.android.gms@14366020@14.3.66 (040406-213742215):12)
at com.google.android.chimera.Activity.publicOnCreate(:com.google.android.gms@14366020@14.3.66 (040406-213742215))
at dlk.onCreate(:com.google.android.gms@14366020@14.3.66 (040406-213742215):6)
at ojt.onCreate(:com.google.android.gms@14366020@14.3.66 (040406-213742215):2)
at android.app.Activity.performCreate(Activity.java:6583)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2531)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Suppressed: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
这是我的地点选择器活动课程-
private fun isGooglePlayServicesAvailable(context: Context): Boolean {
val googleApiAvailability = GoogleApiAvailability.getInstance()
val resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context)
return resultCode == ConnectionResult.SUCCESS
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
activity = this
context = this
location_picker_btn.setOnClickListener {
if (isGooglePlayServicesAvailable(activity)) {
try {
val builder = PlacePicker.IntentBuilder()
activity.startActivityForResult(builder.build(activity), PLACE_PICKER_REQUEST)
} catch (e: Exception) {
e.printStackTrace()
}
} else {
Toast.makeText(activity, "GooglePlayServices Not available", Toast.LENGTH_LONG).show()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == Activity.RESULT_OK && data != null) {
val place = PlacePicker.getPlace(data, this)
val toastMsg = String.format("Place: %s", place.name)
text.text = toastMsg
}
}
}
这是我的毕业班-
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.admin.getdesiredmaplocation"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'GoogleAppIndexingWarning'
baseline file("AndroidManifest.xml") // your choice of filename/path here
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services-places:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
任何建议如何解决这个问题。谢谢