" IBitmapDesc​​riptorFactory未初始化"错误 [英] "IBitmapDescriptorFactory is not initialized" error

查看:1229
本文介绍了" IBitmapDesc​​riptorFactory未初始化"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个标志,在谷歌地图Android的API V2的自定义图标。我只是改变了谷歌提供了一个例子。我加了 .icon(BitmapDesc​​riptorFactory.fromResource(R.drawable.arrow))来RawMapViewDemoActivity的方法 setUpMap()。

I'm trying to get a marker with an custom icon in Google Maps Android API v2. I just changed one of the examples Google provides. I added .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)) to RawMapViewDemoActivity in method setUpMap().

private void setUpMapIfNeeded() {
    if (mMap == null) {
        mMap = ((MapView) findViewById(R.id.map)).getMap();
        if (mMap != null) {
            setUpMap();
        }
    }
}

private void setUpMap() {
    mMap.addMarker(new MarkerOptions()
        .position(new LatLng(0, 0))
        .title("Marker")
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
}

不过,我总是得到一个IBitmapDesc​​riptorFactory未初始化。

But I'm always getting an "IBitmapDescriptorFactory is not initialized".

12-18 15:40:54.356: E/AndroidRuntime(12591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.RawMapViewDemoActivity}: java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.os.Looper.loop(Looper.java:137)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread.main(ActivityThread.java:4745)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at java.lang.reflect.Method.invokeNative(Native Method)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at java.lang.reflect.Method.invoke(Method.java:511)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at dalvik.system.NativeStart.main(Native Method)
12-18 15:40:54.356: E/AndroidRuntime(12591): Caused by: java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.google.android.gms.internal.at.a(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.google.android.gms.maps.model.BitmapDescriptorFactory.d(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.google.android.gms.maps.model.BitmapDescriptorFactory.fromResource(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.example.mapdemo.RawMapViewDemoActivity.setUpMap(RawMapViewDemoActivity.java:67)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.example.mapdemo.RawMapViewDemoActivity.setUpMapIfNeeded(RawMapViewDemoActivity.java:58)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at com.example.mapdemo.RawMapViewDemoActivity.onCreate(RawMapViewDemoActivity.java:43)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.Activity.performCreate(Activity.java:5008)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-18 15:40:54.356: E/AndroidRuntime(12591):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-18 15:40:54.356: E/AndroidRuntime(12591):    ... 11 more

在<一个href="https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory">BitmapDescriptorFactory它说:

此前使用从这个类的任何方法,必须执行下列操作之一,以确保这个类初始化:

Prior to using any methods from this class, you must do one of the following to ensure that this class is initialized:

      
  • 等待一个GoogleMap的成为可从已添加到您的应用程序MapFragment或图形页面。您可以验证的GoogleMap的可调用的GetMap()方法,并检查返回的对象不为空。

  • Wait for a GoogleMap to become available from a MapFragment or MapView that you have added to your application. You can verify that the GoogleMap is available by calling the getMap() method and checking that the returned object is not null.

呼叫MapsInitializer.initialize(上下文)。只要com.google.android.gms.common.GooglePlayServicesNotAvailableException GooglePlayServicesNotAvailableException不抛出,这个类将被正确初始化。

Call MapsInitializer.initialize(Context). As long as a com.google.android.gms.common.GooglePlayServicesNotAvailableException GooglePlayServicesNotAvailableException isn't thrown, this class will be correctly initialized.

我做了第一个,但还是收到这个错误。有什么建议?

I did the first one, but still getting this error. Any suggestions?

推荐答案

呼叫 MapsInitializer.initialize(getApplicationContext())的onCreate()

这篇关于&QUOT; IBitmapDesc​​riptorFactory未初始化&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆