我正在使用库Searchable Spinner,但是当我打开微调器时按下android主页按钮或多任务按钮,应用程序崩溃并在屏幕上打印:“不幸的是,Appname已经停止了。” / p>
我的片段活动:
public class buscadorFragment extends Fragment implements View.OnClickListener {
public Button BotonRecargar;
public IndeterminateRoadRunner UCargando;
public TextView TextoPrueba;
public TextView TextoError;
private OnFragmentInteractionListener mListener;
public SearchableSpinner SpCateg;
public SearchableSpinner SpUbic;
String[] CategoriasArray = {"Categorias"};
String[] UbicacionesArray ={"Ubicaciones"};
ArrayAdapter<String> CatspinnerAdapter;
ArrayAdapter<String> UbicspinnerAdapter;
public buscadorFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_buscador, container, false);
CatspinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, CategoriasArray);
CatspinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
SpCateg.setAdapter(CatspinnerAdapter);
CatspinnerAdapter.notifyDataSetChanged();
UbicspinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, UbicacionesArray);
UbicspinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
SpUbic.setAdapter(UbicspinnerAdapter);
UbicspinnerAdapter.notifyDataSetChanged();
SpCateg.setTitle("Categoría");
SpCateg.setPositiveButton("Cancelar");
SpUbic.setTitle("Ubicación");
SpUbic.setPositiveButton("Cancelar");
return view;
}
我的片段布局:
仅添加
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:id="@+id/Category_Spinner" />
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:id="@+id/Ubication_Spinner" />
</LinearLayout>
有logcat:
08-31 20:09:21.656 18172-18172/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kreativer.upy, PID: 18172
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner)
at android.os.Parcel.writeSerializable(Parcel.java:1323)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.FragmentState.writeToParcel(Fragment.java:133)
at android.os.Parcel.writeTypedArray(Parcel.java:1140)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:373)
at android.os.Parcel.writeParcelable(Parcel.java:1292)
at android.os.Parcel.writeValue(Parcel.java:1211)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2643)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3252)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5426)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.NotSerializableException: android.widget.ArrayAdapter
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at android.os.Parcel.writeSerializable(Parcel.java:1318)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.FragmentState.writeToParcel(Fragment.java:133)
at android.os.Parcel.writeTypedArray(Parcel.java:1140)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:373)
at android.os.Parcel.writeParcelable(Parcel.java:1292)
at android.os.Parcel.writeValue(Parcel.java:1211)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2643)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3252)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5426)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
仅在微调器打开时崩溃,否则应用程序继续运行。 我是新手,想要学习,所以提前谢谢。
答案 0 :(得分:1)
看起来这是库的问题,因为其他用户在Github上报告了同样的问题。 要解决此问题,可以在onPause()方法中关闭searchableListDialog。
请在Application.Restart();
SearchableListDialog.java
答案 1 :(得分:0)
将此库添加到应用程序的 gradle 文件中的依赖项中:
实现'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'