2017-08-20 130 views
0

我想通過這種方法來獲得從地址緯度和經度: -java.lang.NoClassDefFoundError:失敗分辨率:LCOM /谷歌/安卓/地圖/ GeoPoint的

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: Failed resolution of: Lcom/google/android/maps/GeoPoint

我在這裏錯過了什麼?

我的全錯誤: -

Process: breamex.happy_week_end, PID: 22803 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/maps/GeoPoint; at breamex.happy_week_end.search.SearchActivity.getLocationFromAddress(SearchActivity.java:439) at breamex.happy_week_end.search.SearchActivity.search(SearchActivity.java:357) at breamex.happy_week_end.search.SearchActivity.access$000(SearchActivity.java:76) at breamex.happy_week_end.search.SearchActivity$1.onClick(SearchActivity.java:189) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22265) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.maps.GeoPoint" on path: DexPathList[[zip file "/data/app

我的全搖籃: -

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

發表您的完整的錯誤日誌和gradle這個文件 –

+0

@BhuvaneshBs什麼gradle這個會爲你順便說一句,我沒有用它做?這主要錯誤,沒有更多有用的東西? –

+0

你不能定義這是一個確切的錯誤。這個錯誤可能是由其他一些原因造成的。所以發佈完整的錯誤日誌。 –

回答

2

你必須包括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' 

在您的搖籃添加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> 

然後清理並重建您的項目。

希望它hleps :)

相關問題