无法创建群集管理器实例(使用谷歌地图API的Android实用工具库) [英] Cannot create Cluster Manager instance( using Google Maps Android API Utility Library)
问题描述
更新:(问题解决)
最后,它工作在我的 IntelliJ IDEA的13
的问题是,该库未正确导入。
进入项目结构下,选择模块,从现有的源添加库作为模块,
然后点击它,它会显示的 Android版并选中它作为库模块,然后它会工作
即时通讯使用谷歌地图Android版API工具库
我的应用程序。如果我创建一个实例,GoogleMap的移动摄像头的具体位置,它的作品! code可以在下面找到。
不幸的是,如果我调用 mClusterManager =新ClusterManager< MyItem>(这一点,MMAP);
和添加项目,应用程序会崩溃。任何人都可以帮忙吗?这到底是怎么回事呢?
公共类MapActivity扩展FragmentActivity { 私人GoogleMap的MMAP;
私人ClusterManager< MyItem> mClusterManager; @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.map);
setUpMapIfNeeded();
} @覆盖
保护无效onResume(){
super.onResume();
setUpMapIfNeeded();
} setUpMapIfNeeded私人无效(){
如果(MMAP!= NULL){
返回;
}
MMAP =((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap();
如果(MMAP!= NULL){
//如果注释掉mCLusterManager实例,应用工程和显示地图
// mClusterManager =新ClusterManager< MyItem>(这一点,MMAP); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(新经纬度(51.5,-0.35),9));
}
}
}
下面是map.xml(从 https://github.com/googlemaps/得到了它Android的地图-utils的)
<?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:地图=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:名字=com.google.android.gms.maps.SupportMapFragment/>
在logcat的错误:
10-02 18:13:08.667 2854年至2854年/ your.androidclient E / AndroidRuntime:致命异常:主要
java.lang.NoClassDefFoundError的:com.google.maps.android.clustering.ClusterManager
在your.androidclient.AndroidClientActivity.setUpMapIfNeeded(AndroidClientActivity.java:115)
在your.androidclient.AndroidClientActivity.onCreate(AndroidClientActivity.java:99)
在android.app.Activity.performCreate(Activity.java:5008)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
在android.app.ActivityThread.access $ 600(ActivityThread.java:130)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1195)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4745)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
在LogCat中的状态
java.lang.NoClassDefFoundError的:com.google.maps.android.clustering.ClusterManager
这意味着地图-utils的库不会被添加到您的最终APK。你加它作为一个库(项目属性> Android的>库)?
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
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)
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)?
这篇关于无法创建群集管理器实例(使用谷歌地图API的Android实用工具库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!