miteshpithadiya / SearchableSpinner

Spinner with searchable items.
674 stars 241 forks source link

Fatal Exception: java.lang.RuntimeException: Parcelable encountered IOException #55

Open AnithJo opened 7 years ago

AnithJo commented 7 years ago

Fatal Exception: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner)

ponnamkarthik commented 7 years ago

can you provide the code

AnithJo commented 7 years ago

ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, arrayItems);

    searchSpinner.setAdapter(adapter);

    searchSpinner.setOnItemSelectedListener(new

AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Log.v("item", (String) parent.getItemAtPosition(position));

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });

On Wed, Jul 19, 2017 at 2:17 PM, Karthik Ponnam notifications@github.com wrote:

can you provide the code

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/miteshpithadiya/SearchableSpinner/issues/55#issuecomment-316316882, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac1b-2qyZPyorHpyBrKF_IULTkjxzJsPks5sPcK4gaJpZM4OZ910 .

ponnamkarthik commented 7 years ago

what data type is arrayItems?

AnithJo commented 7 years ago

String only.. ArrayList arrayItems = new ArrayList();

On Sun, Jul 23, 2017 at 3:48 PM, Karthik Ponnam notifications@github.com wrote:

what data type is arrayItems?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/miteshpithadiya/SearchableSpinner/issues/55#issuecomment-317242981, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac1b-67tw2-OFBP8mQ-NEwkjLzl8dNK_ks5sQx4EgaJpZM4OZ910 .

AnithJo commented 7 years ago

Is there any solution for this?

ponnamkarthik commented 7 years ago

i was unable to replicate the error

Can you upload your sample project

lakshyapunhani commented 6 years ago

Hi, I got the same issue. Please find a solution for this ASAP

bsoto24 commented 6 years ago

Well, I solved this problem.

I don't know if it's completely correct but it works for me:

Hi, i got the same issue, when the dialog is active and my activity is: onPause() or onStop() my app crashes, another issue occurs when I double click on the spinner before the dialog opened (It was solved by creating a CustomSearchableSpinner, a solution of @ashwindmk)

Error: AndroidRuntime: FATAL EXCEPTION: main Process: com.openlab.laacademiaapp, PID: 7632 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.openlab.XXXXXXXXXX.widget.CustomSearchableSpinner)

Solution:

  1. Create CustomSearchableSpinner and implements Parcelable
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.toptoche.searchablespinnerlibrary.SearchableSpinner;

@SuppressLint("ParcelCreator")
public class CustomSearchableSpinner extends SearchableSpinner implements Parcelable{

     public static boolean isSpinnerDialogOpen = false;

     public CustomSearchableSpinner(Context context) {
         super(context);
     }

     public CustomSearchableSpinner(Context context, AttributeSet attrs) {
         super(context, attrs);
     }

     public CustomSearchableSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
     }

     @Override
     public boolean onTouch(View v, MotionEvent event) {
         if (event.getAction() == MotionEvent.ACTION_UP) {
             if (!isSpinnerDialogOpen) {
                 isSpinnerDialogOpen = true;
                 return super.onTouch(v, event);
             }
             isSpinnerDialogOpen = false;
         }
         new Handler().postDelayed(new Runnable() {
             @Override
             public void run() {
                 isSpinnerDialogOpen = false;
             }
         }, 500);
         return true;
     }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }
}
favaspm commented 6 years ago

thank you

c0dehunter commented 5 years ago

Why is this fix not merged into the library? I use SearchableSpinner (it's great!) throughout my app but sadly I get this crash report too. I am not able to reproduce it and stack traces do not show where exactly this occurrs.

makunomark commented 5 years ago

@pepitofriki Your solution works great! Thanks for that. However, I am now facing another issue that I suspect is caused by @SuppressLint("ParcelCreator"). The log reads as:

Caused by android.os.BadParcelableException
Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.xxxx.xxxx.SearchableSpinnerCustom

I tried to create the CREATOR object, sadly I am unable to because I need a Context object when creating my custom spinner. Any ideas on how to move from here?

CleatonPais commented 4 years ago

Well, I solved this problem.

I don't know if it's completely correct but it works for me:

Hi, i got the same issue, when the dialog is active and my activity is: onPause() or onStop() my app crashes, another issue occurs when I double click on the spinner before the dialog opened (It was solved by creating a CustomSearchableSpinner, a solution of @ashwindmk)

Error: AndroidRuntime: FATAL EXCEPTION: main Process: com.openlab.laacademiaapp, PID: 7632 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.openlab.XXXXXXXXXX.widget.CustomSearchableSpinner)

Solution:

  1. Create CustomSearchableSpinner and implements Parcelable
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.toptoche.searchablespinnerlibrary.SearchableSpinner;

@SuppressLint("ParcelCreator")
public class CustomSearchableSpinner extends SearchableSpinner implements Parcelable{

     public static boolean isSpinnerDialogOpen = false;

     public CustomSearchableSpinner(Context context) {
         super(context);
     }

     public CustomSearchableSpinner(Context context, AttributeSet attrs) {
         super(context, attrs);
     }

     public CustomSearchableSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
     }

     @Override
     public boolean onTouch(View v, MotionEvent event) {
         if (event.getAction() == MotionEvent.ACTION_UP) {
             if (!isSpinnerDialogOpen) {
                 isSpinnerDialogOpen = true;
                 return super.onTouch(v, event);
             }
             isSpinnerDialogOpen = false;
         }
         new Handler().postDelayed(new Runnable() {
             @Override
             public void run() {
                 isSpinnerDialogOpen = false;
             }
         }, 500);
         return true;
     }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }
}

Thanks this solved both my problems 1) when onPause and onStop when the spinner is open 2) double click on the spinner

ShubhamShinde33 commented 4 years ago

This solution worked perfectly, thanks for that...