2

Update:(Problem solved) FInally it is working in my Intellij Idea 13

The problem is that the library was not imported correctly. Go Project Structure, select Modules, add the library as module from an existing source, then click it, it will show Android and check it as Library Module, then it would work

enter image description here enter image description here

Im using Google Maps Android API Utility Library in my app. If i create a GoogleMap instance and move camera to specific location, it works! Code can be found below.

Unfortunately if I invoke mClusterManager = new ClusterManager<MyItem>(this, mMap); and add items to it, the app will crash. Can anyone help? What is going on here?

public class MapActivity  extends  FragmentActivity{

    private GoogleMap mMap;
    private ClusterManager<MyItem> mClusterManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        if (mMap != null) {
            return;
        }
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (mMap != null) {
            //if comment out mCLusterManager instantiation, the app works and show the map 
            //mClusterManager = new ClusterManager<MyItem>(this, mMap);

           mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.5, -0.35), 9));
        }
    }
}

Below is the map.xml (got it from https://github.com/googlemaps/android-maps-utils)

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:map="http://schemas.android.com/apk/res-auto"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"/>

Errors in logcat:

10-02 18:13:08.667    2854-2854/your.androidclient E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.google.maps.android.clustering.ClusterManager
            at your.androidclient.AndroidClientActivity.setUpMapIfNeeded(AndroidClientActivity.java:115)
            at your.androidclient.AndroidClientActivity.onCreate(AndroidClientActivity.java:99)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
  • *the app will crash* - do you expect us to guess the exception? – user Oct 02 '14 at 17:15
  • im testing it on my phone, it only says "unfortunately app has stopped" , I tried ` Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();` but didnt get anything – Haifeng Zhang Oct 02 '14 at 17:16
  • Did you check the logcat for the exception? – user Oct 02 '14 at 17:23
  • @Luksprog sorry for my late reply, i was setting google maps working for my genymotion last 1 hour and i got the error in the logcat, please see it in the question area. – Haifeng Zhang Oct 02 '14 at 18:14

3 Answers3

4

The docs tell you to use:

compile 'com.google.maps.android:android-maps-utils:0.4+'

Using this will give the error. You must use android-maps-utils:0.4.2

compile 'com.google.maps.android:android-maps-utils:0.4.2'

This will get rid of the error.

note: i posted in another answer to use 0.3+, although 0.4.2 is obviously better. Either way, 0.4+ doesn't work and the others do

Nickmccomb
  • 1,467
  • 3
  • 19
  • 34
  • Thanks to seems to have solved it for me. Very strange fix! (I was also required to use exclude on the library that referred to the 0.4+ version) – Daverix Sep 02 '16 at 18:53
2

The LogCat states

java.lang.NoClassDefFoundError: com.google.maps.android.clustering.ClusterManager

This means that the maps-utils-library is not added to your final APK. Did you add it as a library (Project properties > Android > Library)?

Ridcully
  • 23,362
  • 7
  • 71
  • 86
2

Edit your play services with bellow :

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services-maps:9.2.1'
    compile 'com.google.android.gms:play-services-places:9.2.1'
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}