ошибка при работе с картой

243
06 апреля 2017, 18:18

В портретной ориентации все работает отлично но когда поворачиваю экран программа вылетает.

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/fragment_map_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:elevation="4dp"
            app:popupTheme="@style/AppTheme"
            app:theme="@style/ToolbarTheme"/>

    </android.support.design.widget.AppBarLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_layers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:background="@android:color/white"
        app:useCompatPadding="true"
        android:src="@android:drawable/ic_dialog_info" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_my_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|end"
        android:src="@drawable/ic_map_location"
        app:layout_anchor="@id/fab_layers"
        app:useCompatPadding="true"
        app:backgroundTint="@android:color/white"
        app:layout_anchorGravity="top" />
    <com.google.android.gms.maps.MapView
        android:id="@+id/fragment_map_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

Код фрагмента:

public class FragmentMap extends Fragment implements OnMapReadyCallback {
    private static final String TAG = "FragmentMap";
private FragmentWeatherMain.Callbacks mCallbacks;
private Toolbar mToolbar;
private MapView mMapView;
public static FragmentMap newInstance() {
    return new FragmentMap();
}
@Override
public void onAttach(Activity activity){
    super.onAttach(activity);
    mCallbacks = (FragmentWeatherMain.Callbacks) activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState){
    View view = inflater.inflate(R.layout.fragment_map, container, false);
    getActivity().setTitle(String.format(getResources().getString(R.string.fragment_map_title)));
    mMapView = (MapView) view.findViewById(R.id.fragment_map_view);
    mMapView.onCreate(savedInstanceState);
    mMapView.getMapAsync(this);
    mToolbar = (Toolbar) view.findViewById(R.id.fragment_map_toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(true);
    mCallbacks.onDrawerToggleClick(mToolbar);
    return view;
}
@Override
public void onStart() {
    super.onStart();
    mMapView.onStart();
}
@Override
public void onResume() {
    super.onResume();
    mMapView.onResume();
}
@Override
public void onPause() {
    super.onPause();
    mMapView.onPause();
}
    @Override
    public void onStop() {
        super.onStop();
        mMapView.onStop();
    }
    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }
    @Override
    public void onDetach(){
        super.onDetach();
        mCallbacks = null;
    }
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }
    @Override
    public void onMapReady(GoogleMap googleMap) {
    }
}

Ошибка:

Class not found when unmarshalling: android.support.v7.widget.Toolbar$SavedState
                                                                           java.lang.ClassNotFoundException: android.support.v7.widget.Toolbar$SavedState
                                                                               at java.lang.Class.classForName(Native Method)
                                                                               at java.lang.Class.forName(Class.java:324)
                                                                               at android.os.Parcel.readParcelableCreator(Parcel.java:2404)
                                                                               at android.os.Parcel.readParcelable(Parcel.java:2358)
                                                                               at android.os.Parcel.readValue(Parcel.java:2264)
                                                                               at android.os.Parcel.readSparseArrayInternal(Parcel.java:2675)
                                                                               at android.os.Parcel.readSparseArray(Parcel.java:1967)
                                                                               at android.os.Parcel.readValue(Parcel.java:2321)
                                                                               at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
                                                                               at android.os.BaseBundle.unparcel(BaseBundle.java:221)
                                                                               at android.os.Bundle.getBundle(Bundle.java:763)
                                                                               at com.google.android.gms.maps.internal.ea.a(:com.google.android.gms.DynamiteModulesB:168)
                                                                               at com.google.maps.api.android.lib6.impl.az.a(:com.google.android.gms.DynamiteModulesB:690)
                                                                               at com.google.maps.api.android.lib6.impl.da.a(:com.google.android.gms.DynamiteModulesB:81)
                                                                               at com.google.android.gms.maps.internal.z.onTransact(:com.google.android.gms.DynamiteModulesB:66)
                                                                               at android.os.Binder.transact(Binder.java:387)
                                                                               at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate(Unknown Source)
                                                                               at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source)
                                                                               at com.google.android.gms.dynamic.zza$3.zzb(Unknown Source)
                                                                               at com.google.android.gms.dynamic.zza$1.zza(Unknown Source)
                                                                               at com.google.android.gms.maps.MapView$zzb.zzIL(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 com.example.jeka.exampledrawerbar.fragments.FragmentMap.onCreateView(FragmentMap.java:39)
                                                                               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 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                               at android.app.Activity.performStart(Activity.java:6943)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3276)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
                                                                               at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5472)
                                                                               at android.app.ActivityThread.access$1200(ActivityThread.java:229)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1827)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:148)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                            Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar$SavedState" on path: DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/0000001b/DynamiteModulesB_GmsCore_prodmnc_xhdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/0000001b/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/0000001b/n/armeabi, /vendor/lib, /system/lib]]
                                                                               at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                               at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                            at bzi.loadClass(:com.google.android.gms:34
Answer 1

Попробуйте как тут советуют отделить при сохранении/восстановлении состояние карты от состояния фрагмента так:

// class property
private static final String KEY_MAP_SAVED_STATE = "mapState";
// class methods
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mapView = ...;
    Bundle mapState = (savedInstanceState != null)
            ? savedInstanceState.getBundle(KEY_MAP_SAVED_STATE): null;
    mapView.onCreate(mapState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Bundle mapState = new Bundle();
    mapView.onSaveInstanceState(mapState);
    outState.putBundle(KEY_MAP_SAVED_STATE, mapState);
}
READ ALSO
Canvas размеры полотна

Canvas размеры полотна

Создал свой виджет, но не могу понять как образуется размер для холстаРазмер экрана эмулятора 1280х768

225
Загрузка png без потери качества из drawble

Загрузка png без потери качества из drawble

Имеется png в drawble, фон для приложения и весит 70 кбайтГрадиент на нем плавный, png-24 с еще 8 битами на канал для прозрачности

206
Хранение настроек Swing приложения

Хранение настроек Swing приложения

Делаю приложуху на SwingНужно сохранять настройки приложения, но так что бы юзер не мог добраться до него, по крайней мере что б это был не файл...

312
Установка фокуса на EditText

Установка фокуса на EditText

В xml у editText есть эти 2 атрибута:

313