更新:(问题已解决)最终它在我的Intellij Idea 13中工作
问题是没有正确导入库。转到 Project Structure,选择Modules,将库添加为来自现有源的模块,然后单击它,它将显示Android并将其选中为Library Module,然后它就可以工作了
我Google Maps Android API Utility Library
在我的应用程序中使用。如果我创建一个 GoogleMap 实例并将相机移动到特定位置,它就可以工作!代码可以在下面找到。
不幸的是,如果我调用mClusterManager = new ClusterManager<MyItem>(this, mMap);
并向其添加项目,应用程序将崩溃。任何人都可以帮忙吗?这里发生了什么?
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));
}
}
}
下面是 map.xml(从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"/>
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)