仅使用最新的GooglePlayServices的onCreate中的MapView NullPointerException

时间:2018-10-11 18:50:21

标签: java android xml google-play-services android-mapview

我一直在维护一个使用MapView的应用程序,最近我在尝试调用MapView的onCreate()方法时遇到了NullPointerExceptions的问题。奇怪的是,这仅发生在较新版本的Google Play服务上。当我将版本恢复为出厂默认设置时,MapView可以正常工作。也就是说,适用于9.8.79,不适用于14.3.66。不能在所有生产型手持设备上更改Play服务的版本。

我尝试过的事情

  1. 检查API密钥:不是问题。无论如何都不可能做到这一点,因为它也不能与旧版本的Play服务一起使用。
  2. 将play-services-maps依赖关系从8.4.0(默认为过去)更新为最新的16.0.0。尽管这清除了异常,但MapView从未设法完成初始化。它所做的只是在文本“ Google Play服务正在更新”中渲染了一个黑色空间,尽管实际上它已更新为14.3.66。
  3. 使用MapsInitializer.initialize()进行预初始化;由于docs会说getMapAsync()自动完成此操作,因此不需要这样做,但是无论如何我还是给了它一个机会。行为没有变化。
  4. 已检查的布局文件。我真的希望这是问题所在,但是findViewById()返回了有效的引用,所以没有运气。

这里有几个标题相似的问题,所以我想现在就抢先使用[重复]标签。我见过的每个其他问题在堆栈跟踪中都有不同的详细信息,建议的答案要么不适用,要么不适用于我的问题。

LogCat

10-11 10:36:59.644 2386-2386/net.xconsulting.fairtrak E/DynamiteLoaderImpl: Error creating module context: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
10-11 10:36:59.680 2386-2386/net.xconsulting.fairtrak E/AndroidRuntime: FATAL EXCEPTION: main
    Process: net.xconsulting.fairtrak, PID: 2386
    java.lang.RuntimeException: Unable to start activity ComponentInfo{net.xconsulting.fairtrak/net.xconsulting.fairtrak.activity.NotesActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2547)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2613)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1469)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5692)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
        at android.content.ContentResolver.checkLeakDetectIgnoreList(ContentResolver.java:2695)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1178)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:958)
        at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:811)
        at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:765)
        at tns.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):33)
        at tns.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):11)
        at com.google.android.gms.chimera.container.DynamiteLoaderImpl.createModuleContextNoCrashUtils(:com.google.android.gms@14366020@14.3.66 (040406-213742215):11)
        at com.google.android.gms.dynamite.DynamiteModule.b(:com.google.android.gms@14366020@14.3.66 (040406-213742215):12)
        at com.google.android.gms.dynamite.DynamiteModule.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):53)
        at com.google.android.gms.dynamite.DynamiteModule.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):76)
        at oky.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):1)
        at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):8)
        at com.google.android.gms.maps.internal.CreatorImpl.newMapViewDelegate(:com.google.android.gms@14366020@14.3.66 (040406-213742215):1)
        at actl.a(:com.google.android.gms@14366020@14.3.66 (040406-213742215):21)
        at cje.onTransact(:com.google.android.gms@14366020@14.3.66 (040406-213742215):3)
        at android.os.Binder.transact(Binder.java:392)
        at com.google.android.gms.maps.internal.zzc$zza$zza.zza(Unknown Source)
        at com.google.android.gms.maps.MapView$zzb.zzzW(Unknown Source)
        at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source)
        at com.google.android.gms.dynamic.zza.zza(Unknown Source)
        at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
        at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
        at net.xconsulting.fairtrak.activity.NotesActivity.onCreate(NotesActivity.java:70)
        at android.app.Activity.performCreate(Activity.java:6270)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2500)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2613) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1469) 
        at android.os.Handler.dispatchMessage(Handler.java:111) 
        at android.os.Looper.loop(Looper.java:207) 
        at android.app.ActivityThread.main(ActivityThread.java:5692) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769) 

代码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notes);

        MapView mapView = findViewById(R.id.noteMap);

        mapView.getMapAsync(this);
        mapView.onCreate(savedInstanceState);
    }

布局

<com.google.android.gms.maps.MapView
    android:id="@+id/noteMap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

等级依赖性

dependencies {
    implementation 'com.google.android.gms:play-services-maps:8.4.0'
    //also tried implementation 'com.google.android.gms:play-services-maps:16.0.0'
}

0 个答案:

没有答案