SearchableSpinner icon indicating copy to clipboard operation
SearchableSpinner copied to clipboard

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

Open AnithJo opened this issue 7 years ago • 13 comments

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

AnithJo avatar Jul 17 '17 13:07 AnithJo

can you provide the code

ponnamkarthik avatar Jul 19 '17 08:07 ponnamkarthik

ArrayAdapter<String> adapter = new ArrayAdapter<String>(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 [email protected] 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 .

AnithJo avatar Jul 22 '17 07:07 AnithJo

what data type is arrayItems?

ponnamkarthik avatar Jul 23 '17 10:07 ponnamkarthik

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

On Sun, Jul 23, 2017 at 3:48 PM, Karthik Ponnam [email protected] 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 avatar Jul 24 '17 10:07 AnithJo

Is there any solution for this?

AnithJo avatar Aug 07 '17 06:08 AnithJo

i was unable to replicate the error

Can you upload your sample project

ponnamkarthik avatar Aug 07 '17 06:08 ponnamkarthik

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

lakshyapunhani avatar Dec 29 '17 12:12 lakshyapunhani

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) {

    }
}

bsoto24 avatar Feb 01 '18 22:02 bsoto24

thank you

favaspm avatar Jun 28 '18 07:06 favaspm

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.

c0dehunter avatar Mar 01 '19 08:03 c0dehunter

@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?

makunomark avatar Apr 29 '19 08:04 makunomark

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

CleatonPais avatar Jan 28 '20 08:01 CleatonPais

This solution worked perfectly, thanks for that...

ShubhamShinde33 avatar May 29 '20 07:05 ShubhamShinde33