I want save a Contacto's item on a RecyclerView from a NewContact class by intent. In my Contactos class I have a Bitmap and I know this is the error becuase, before, without bitmap works it. What's wrong?
Contactos class:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.Serializable;
public class Contactos implements Serializable{
private String Nombre;
private String Apellidos;
private String Telefono;
private String Correo;
private Bitmap Foto;
public Contactos(){
}
public Contactos(String nombre, String apellidos, String telefono, String correo) {
Nombre = nombre;
Apellidos = apellidos;
Telefono = telefono;
Correo = correo;
}
public Contactos(String nombre, String apellidos, String telefono, String correo, Bitmap foto) {
Nombre = nombre;
Apellidos = apellidos;
Telefono = telefono;
Correo = correo;
Foto = foto;
}
public String getNombre() {
return Nombre;
}
public void setNombre(String nombre) {
Nombre = nombre;
}
public String getApellidos() {
return Apellidos;
}
public void setApellidos(String apellidos) {
Apellidos = apellidos;
}
public String getTelefono() {
return Telefono;
}
public void setTelefono(String telefono) {
Telefono = telefono;
}
public String getCorreo() {
return Correo;
}
public void setCorreo(String correo) {
Correo = correo;
}
public Bitmap getFoto() {
return Foto;
}
public void setFoto(Bitmap foto) {
Foto = foto;
}
}
and Holder class:
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class Holder extends RecyclerView.ViewHolder {
TextView txtnombre;
TextView txtapellido;
TextView txttelefono;
TextView txtemail;
ImageView iVFoto;
public Holder(View itemView) {
super(itemView);
txtnombre = (TextView)itemView.findViewById(R.id.txtNombre);
txtapellido = (TextView)itemView.findViewById(R.id.txtApellidos);
txttelefono = (TextView)itemView.findViewById(R.id.txtTelefono);
txtemail = (TextView)itemView.findViewById(R.id.txtCorreo);
iVFoto = (ImageView)itemView.findViewById(R.id.foto);
}
public void bind(Contactos c){
txtnombre.setText(c.getNombre());
txtapellido.setText(c.getApellidos());
txttelefono.setText(c.getTelefono());
txtemail.setText(c.getCorreo());
//iVFoto.setImageDrawable(new BitmapDrawable(getResources(), c.getFoto())); me marca en ROJO getResources() y me pone que está en desuso(tachado) BitmapDrawable
iVFoto.setImageDrawable(new BitmapDrawable(c.getFoto()));
}
public TextView getTxtnombre() {
return txtnombre;
}
public TextView getTxtapellido() {
return txtapellido;
}
public TextView getTxttelefono() {
return txttelefono;
}
public TextView getTxtemail() {
return txtemail;
}
public ImageView getiVFoto() {
return iVFoto;
}
}
And the logcat
11-06 10:04:48.185 28245-28245/com.example.jorge.ejerciciopropuestoagenda E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jorge.ejerciciopropuestoagenda, PID: 28245
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.jorge.ejerciciopropuestoagenda.Contactos)
at android.os.Parcel.writeSerializable(Parcel.java:1394)
at android.os.Parcel.writeValue(Parcel.java:1341)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1034)
at android.os.Parcel.writeBundle(Parcel.java:669)
at android.content.Intent.writeToParcel(Intent.java:7496)
at android.app.ActivityManagerProxy.finishActivity(ActivityManagerNative.java:2725)
at android.app.Activity.finish(Activity.java:4662)
at android.app.Activity.finish(Activity.java:4680)
at com.example.jorge.ejerciciopropuestoagenda.NuevoContacto.onClick(NuevoContacto.java:55)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.io.NotSerializableException: android.graphics.Bitmap
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1389)
at android.os.Parcel.writeValue(Parcel.java:1341)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1034)
at android.os.Parcel.writeBundle(Parcel.java:669)
at android.content.Intent.writeToParcel(Intent.java:7496)
at android.app.ActivityManagerProxy.finishActivity(ActivityManagerNative.java:2725)
at android.app.Activity.finish(Activity.java:4662)
at android.app.Activity.finish(Activity.java:4680)
at com.example.jorge.ejerciciopropuestoagenda.NuevoContacto.onClick(NuevoContacto.java:55)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)