-1

我们使用 firebase crashlytics 来监控生产中的崩溃,自从更新到 3.18 后,我们在生产(发布)中遇到了这个错误,这在开发中从未发生过。我认为错误出现在 Here's source code 中,因为我在 init 方法之前进行了空检查。

Fatal Exception: java.lang.NullPointerException: Context is null
       at java.util.Objects.requireNonNull(Objects.java:228)
       at com.nokia.maps.f4.a(Preconditions.java:1)
       at com.nokia.maps.v.<init>(AppContextImpl.java:13)
       at com.here.android.mpa.common.ApplicationContext.<init>(ApplicationContext.java:2)
       at com.here.android.mpa.mapping.AndroidXMapFragment.init(AndroidXMapFragment.java:1)
       at my.package.app.fragments.navegacionhere.MapFragmentView.initMapFragment(MapFragmentView.java:538)
       at my.package.app.fragments.navegacionhere.MapFragmentView.<init>(MapFragmentView.java:160)
       at my.package.app.activity.llamadas.DetalleLlamadaActivity.setupMapFragmentView(DetalleLlamadaActivity.java:1339)
4

1 回答 1

0

一般来说,这个异常发生在 AndroidXMapFragment.init(...) 中,当 Activity 没有被附加到 Fragment 时。如果 fragment.getActivity() 为 null,您可以使用下面的方法,并为 ApplicatoinContext 构造函数提供任何 Android 上下文,它不应该是 Activity 的上下文。 https://developer.here.com/documentation/android-premium/3.18/api_reference_java/com/here/android/mpa/mapping/AndroidXMapFragment.html#init-com.here.android.mpa.common.ApplicationContext-com。这里.android.mpa.common.OnEngineInitListener-

public void init(@NonNull
ApplicationContext context,
@NonNull
OnEngineInitListener listener)
Initializes the MapEngine and displays a map that occupies the entire AndroidXMapFragment's view rectangle. Users of AndroidXMapFragment should call this method after the fragment is first attached to its activity.
This method can be used for AndroidXMapFragment objects that are created programmatically or declared in a layout XML file.

This method will initialize MapEngine with ApplicationContext to be used during initialization.

Parameters:
context - ApplicationContext to be used during initialization.
listener - A OnEngineInitListener object that will be called when AndroidXMapFragment initialization is finished. A null object can be supplied if the caller does not require any notification when initialization completes.
See Also:
OnEngineInitListener, MapEngine.init(ApplicationContext, OnEngineInitListener)

应用程序上下文

public ApplicationContext(@NonNull
android.content.Context ctx)
Creates a ApplicationContext with specified application context.
Parameters:
ctx - Application context.

上述代码链接:https ://developer.here.com/documentation/android-premium/3.18/api_reference_java/com/here/android/mpa/common/ApplicationContext.html#ApplicationContext-android.content.Context-

为了进一步调查,我们需要用于空检查的代码片段。

于 2021-09-07T11:40:34.460 回答