gpt4 book ai didi

android - Activity 的 OnStart() 中的 SKMaps Android 跟踪错误

转载 作者:行者123 更新时间:2023-11-29 01:12:45 26 4
gpt4 key购买 nike

我最近升级了我的应用程序以使用 SKMaps 3.0.2,一切似乎都正常,除了当我的 Activity (“ViewLocationActivity”)调用扩展 android.support.v4.app.Fragment 的 fragment ( “NewMapFragment”)在后台重启一段时间后,调用 onStart() 方法,Fragment 无法膨胀 SKMapViewHolder 并崩溃。我附上了日志,但看起来这是因为声明的行

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.skobbler.ngx.map.SKMapViewStyle.getStyleFileName()' on a null object reference at com.skobbler.ngx.map.SKMapViewHolder.a(SourceFile:254)

这在以前的 SDK 版本中没有发生,特别奇怪,因为它不会在第一次加载 Fragment 时发生,而只会在随后的重启中,当调用 onStart() 时发生。

相关代码 fragment

@Override
public void onStart() // In ViewLocationActivity {
super.onStart();
Intent intent = new Intent(this, LocationService.class);
bindService(intent, mConnection, BIND_AUTO_CREATE);
}



public void onCreate(Bundle savedInstanceState) // in NewMapFragment {
super.onCreate(savedInstanceState);
Methods.initializeSKMaps(getActivity());
locationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
registerLocationListener();
SKCurrentPositionProvider currentPositionProvider = new SKCurrentPositionProvider(getActivity());
currentPositionProvider.setCurrentPositionListener(this);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) // in NewMapFragment {
// App crashes in this line
mView = inflater.inflate(R.layout.fragment_new_map, container, false);
mapHolder = (SKMapViewHolder)mView.findViewById(R.id.map_surface_holder);
mapHolder.setMapSurfaceListener(this);
initializeControlButtons();
initializeBottomSheet();
return mView;
}

<!-- fragment_new_map -->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/skobbler_map_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.skobbler.ngx.map.SKMapViewHolder
android:id="@+id/map_surface_holder"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="@layout/map_control_layout"
android:id="@+id/map_control_layout"/>
</android.support.design.widget.CoordinatorLayout>

日志:

01-23 20:40:51.548 19453-19453/com.shay.vagabond E/AndroidRuntime: FATAL EXCEPTION: main Process: com.shay.vagabond, PID: 19453 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shay.vagabond/com.shay.vagabond.Activities.ViewLocationActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.skobbler.ngx.map.SKMapViewHolder at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.skobbler.ngx.map.SKMapViewHolder Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.skobbler.ngx.map.SKMapViewHolder Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:430) at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at com.shay.vagabond.Fragments.NewMapFragment.onCreateView(NewMapFragment.java:155) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1277) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2154) at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:603) at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181) at com.shay.vagabond.Activities.ViewLocationActivity.onStart(ViewLocationActivity.java:691) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248) at android.app.Activity.performStart(Activity.java:6681) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2609) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.skobbler.ngx.map.SKMapViewStyle.getStyleFileName()' on a null object reference at com.skobbler.ngx.map.SKMapViewHolder.a(SourceFile:254) at com.skobbler.ngx.map.SKMapViewHolder.(SourceFile:159) at java.lang.reflect.Constructor.newInstance0(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:430)  at android.view.LayoutInflater.createView(LayoutInflater.java:645)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)  at android.view.LayoutInflater.inflate(LayoutInflater.java:518)  at android.view.LayoutInflater.inflate(LayoutInflater.java:426)  at com.shay.vagabond.Fragments.NewMapFragment.onCreateView(NewMapFragment.java:155)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1277)  at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2154)  at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:603)  at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181)  at com.shay.vagabond.Activities.ViewLocationActivity.onStart(ViewLocationActivity.java:691)  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248)  at android.app.Activity.performStart(Activity.java:6681)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2609)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)  at android.app.ActivityThread.-wrap12(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6077)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

最佳答案

我不知道这是否是一个理想的解决方案,但由于我没有得到关于 Skobbler SDK 中可能导致此行为的原因的答案,我设法通过简单地删除有问题的 fragment 来解决这个问题,它会膨胀并包含调用 onCreate() 时来自后台堆栈的 SKMapsViewHolder(如果进程被操作系统销毁则调用)。这会强制 Activity 重新初始化并重新创建 Fragment,这似乎可以解决问题。希望它在某些时候对某人有所帮助

    private void initializeViews() {
// Setting the pre-arrival layout
setContentView(R.layout.view_location_layout);
initializeNavigationDrawer();
initializeBottomSheet();
initializeProgressBar();
removeAllFragments();
}

private void removeAllFragments() {
while (fragmentManager.getBackStackEntryCount() > 0)
fragmentManager.popBackStackImmediate();
}

关于android - Activity 的 OnStart() 中的 SKMaps Android 跟踪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41813991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com