1

I have this problem now: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object .. Class Filho implements serializable. How to solve?

public View getView(int position, View view, ViewGroup parent)
{
    final Filho filhoPosition = this.listaFilhos.get(position);
    view = LayoutInflater.from(this.context).inflate(R.layout.lista_filho,null);

    TextView textViewNomeFilho = (TextView) view.findViewById(R.id.textViewNomeFilho);
    TextView textViewTelefoneFilho = (TextView) view.findViewById(R.id.textViewTelefoneFilho);
    ImageView imageViewFotoFilho = (ImageView)  view.findViewById(R.id.imageViewFotoFilho);

    textViewNomeFilho.setText(filhoPosition.getNome());
    textViewTelefoneFilho.setText(filhoPosition.getTelefone());
    imageViewFotoFilho.setImageBitmap(filhoPosition.getFoto());

    final ImageButton imageButtonConfigFilho = (ImageButton) view.findViewById(R.id.imageButtonConfigFilho);
    imageButtonConfigFilho.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){

            filho = new Filho(filhoPosition.getIdFilho(),filhoPosition.getNome(),filhoPosition.getTelefone(),filhoPosition.getFoto(),filhoPosition.getLoginConfig());

            Intent it = new Intent(context, CadastrarFilhoActivity.class);
            it.putExtra("filho",filho);
            context.startActivity(it);
        }
    });
    return view;
}
  • implement `Parcelable` in `Filho`. Using android studio will help need not write code yourself IDE will generate stuff for you – Raghunandan Mar 10 '17 at 06:41

2 Answers2

2

Make Filho class implements Serializable .It is a common problem

That is go to Filho class and implement Serializable

public class Filho class implements Serializable

Edit

Use intent like this you are using putExtra()

Intent it = new Intent(context, CadastrarFilhoActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("filho",filho);
it.putExtras(bundle);

and get by this in CadastrarFilhoActivity.class

Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
Filho filho=(Filho)bundle.getSerializable("filho");
Kiran Benny Joseph
  • 6,755
  • 4
  • 38
  • 57
0

If I put the 4 parameter that is a bitmap like null works, for some reason the bitmap field is giving this problem because I'm not new to java and android and I have no idea how to solve

it.putExtra("filho",new Filho(filhoPosition.getIdFilho(),filhoPosition.getNome(),filhoPosition.getTelefone(),filhoPosition.getFoto(),filhoPosition.getLoginConfig()));