我试图通过这种方法从地址获得经度和经度: -
public GeoPoint getLocationFromAddress(String strAddress){
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(strAddress,5);
if (address==null) {
return null;
}
Address location=address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
return p1;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
但是我得到了错误: -
java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / maps / GeoPoint
我在这里缺少什么?
我的完整错误: -
进程:breamex.happy_week_end,PID:22803 java.lang.NoClassDefFoundError:解析失败: LCOM /谷歌/安卓/地图/ GeoPoint对象; 在 breamex.happy_week_end.search.SearchActivity.getLocationFromAddress(SearchActivity.java:439) 在 breamex.happy_week_end.search.SearchActivity.search(SearchActivity.java:357) 在 breamex.happy_week_end.search.SearchActivity.access $ 000(SearchActivity.java:76) 在 breamex.happy_week_end.search.SearchActivity $ 1.onClick(SearchActivity.java:189) 在android.view.View.performClick(View.java:5610) 在android.view.View $ PerformClick.run(View.java:22265) 在android.os.Handler.handleCallback(Handler.java:751) 在android.os.Handler.dispatchMessage(Handler.java:95) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) 在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 引起:java.lang.ClassNotFoundException:没找到类 路径上的“com.google.android.maps.GeoPoint”:DexPathList [[zip文件 “/数据/应用
我的完整 Gradle : -
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:24'
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "app"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':stepper')
compile project(':slider')
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-messaging:10.2.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.22.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.android.support:support-v4:26.+'
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.jakewharton:butterknife:8.6.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:1)
您必须在应用中包含 multiDex 。 请参阅错误日志中的以下错误。
ClassNotFoundException: Didn't find class "com.google.android.maps.GeoPoint" on path: DexPathList[[zip file "/data/app
将此添加到您的依赖项。
compile 'com.android.support:multidex:1.0.1'
在您的Gradle中添加multiDexEnabled true
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true // add this line
}
...
}
在您的清单中添加 multiDex 应用程序类。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
然后清理并重建您的项目。
希望它能够发挥作用:)