Runtimeexception: Parcelable encountered Ioexception

Asked

Viewed 431 times

2

I can’t understand, let alone run my app.. Someone can give me a light?

@Override
            public void onClick(View arg0) {
                try{
                    Intent i = new Intent(Activity_Questionario.this, Activity_Conf_Inicio_Ques.class);


                    PerguntaAdapter adapter = (PerguntaAdapter) lv.getAdapter();
                    List < Pergunta > ListaPergunta = adapter.getPerguntas();

                    final ArrayList < SerializablePair< Integer, Boolean > > respostas = new ArrayList < SerializablePair< Integer, Boolean > > (ListaPergunta.size());

                    for (Pergunta pergunta: ListaPergunta) {
                        respostas.add(new SerializablePair< Integer, Boolean >(pergunta.getId(), pergunta.getResposta()));
                    }

                    Log.i("Verificação", "Verificando: " + respostas);
                    //Log.i("Senha no Click", "Senha: " + senha);

                    i.putExtra("respostas", respostas);

                    startActivity(i);

                }catch(Exception erro){
                    erro.printStackTrace();
                }
            }
        });

And the other class that gets the values... I believe the error is giving in this line of Arraylist

try{
            ArrayList<SerializablePair<Integer, Boolean>> respostas = (ArrayList<SerializablePair<Integer, Boolean>>) getIntent().getSerializableExtra("respostas");
            Log.i("Respostas na Confirmação", "Respostas: "+respostas);

            String urlPost = "http://"+l.IP+"/projetotcc/android/respostas.php";
            ArrayList<NameValuePair> parametrosPost = new ArrayList<NameValuePair>();

            for(SerializablePair<Integer, Boolean> item : respostas){

                Log.i("Entrou", "Entrou no for(SerializablePair<Integer, Boolean> item : a)");
                parametrosPost.add(new BasicNameValuePair("codigoQuestionario", item.first.toString()));
                parametrosPost.add(new BasicNameValuePair("codigoPaciente", item.second.toString()));

            }

        }catch(Exception erro){
            erro.printStackTrace();
            Toast.makeText(this, "Erro: "+erro, Toast.LENGTH_LONG).show();

        }

Logcat:

10-17 14:12:39.090: W/System.err(2785): java.lang.Runtimeexception: Parcelable encountered Ioexception Reading a Serializable Object (name = br.com.projetotcc.utilitarios.Serializablepair) 10-17 14:12:39.100: W/System.err(2785): at android.os.Parcel.readSerializable(Parcel.java:2144) 10-17 14:12:39.100: W/System.err(2785): at android.os.Parcel.readValue(Parcel.java:2016) 10-17 14:12:39.110: W/System.err(2785): at android.os.Parcel.readListInternal(Parcel.java:2235) 10-17 14:12:39.110: W/System.err(2785): at android.os.Parcel.readArrayList(Parcel.java:1655) 10-17 14:12:39.120: W/System.err(2785): at android.os.Parcel.readValue(Parcel.java:1986) 10-17 14:12:39.130: W/System.err(2785): at android.os.Parcel.readMapInternal(Parcel.java:2226) 10-17 14:12:39.130: W/System.err(2785): at android.os.Bundle.unparcel(Bundle.java:223) 10-17 14:12:39.150: W/System.err(2785): at android.os.Bundle.getSerializable(Bundle.java:1254) 10-17 14:12:39.150: W/System.err(2785): at android.content.Intent.getSerializableExtra(Intent.java:4182) 10-17 14:12:39.150: W/System.err(2785): at br.com.projetotcc.visao.Activity_conf_inicio_ques.onCreate(Activity_conf_inicio_ques.java:45) 10-17 14:12:39.162: W/System.err(2785): at android.app.Activity.performCreate(Activity.java:5008) 10-17 14:12:39.162: W/System.err(2785): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 10-17 14:12:39.180: W/System.err(2785): at android.app.Activitythread.performLaunchActivity(Activitythread.java:2023) 10-17 14:12:39.180: W/System.err(2785): at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2084) 10-17 14:12:39.180: W/System.err(2785): at android.app.Activitythread.access$600(Activitythread.java:130) 10-17 14:12:39.190: W/System.err(2785): at android.app.Activitythread$H.handleMessage(Activitythread.java:1195) 10-17 14:12:39.200: W/System.err(2785): at android.os.Handler.dispatchMessage(Handler.java:99) 10-17 14:12:39.200: W/System.err(2785): at android.os.Looper.loop(Looper.java:137) 10-17 14:12:39.210: W/System.err(2785): at android.app.Activitythread.main(Activitythread.java:4745) 10-17 14:12:39.220: W/System.err(2785): at java.lang.reflect.Method.invokeNative(Native Method) 10-17 14:12:39.240: W/System.err(2785): at java.lang.reflect.Method.invoke(Method.java:511) 10-17 14:12:39.240: W/System.err(2785): at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:786) 10-17 14:12:39.251: W/System.err(2785): at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:553) 10-17 14:12:39.260: W/System.err(2785): at Dalvik.system.Nativestart.main(Native Method) 10-17 14:12:39.280: W/System.err(2785): Caused by: java.io.Invalidclassexception: android.util.Pair; Illegalaccessexception 10-17 14:12:39.300: W/System.err(2785): at java.io.Objectstreamclass.resolveConstructorClass(Objectstreamclass.java:694) 10-17 14:12:39.310: W/System.err(2785): at java.io.Objectstreamclass.newInstance(Objectstreamclass.java:655) 10-17 14:12:39.310: W/System.err(2785): at java.io.Objectinputstream.readNewObject(Objectinputstream.java:1816) 10-17 14:12:39.310: W/System.err(2785): at java.io.Objectinputstream.readNonPrimitiveContent(Objectinputstream.java:787) 10-17 14:12:39.329: W/System.err(2785): at java.io.Objectinputstream.readObject(Objectinputstream.java:2003) 10-17 14:12:39.329: W/System.err(2785): at java.io.Objectinputstream.readObject(Objectinputstream.java:1960) 10-17 14:12:39.341: W/System.err(2785): at android.os.Parcel.readSerializable(Parcel.java:2142) 10-17 14:12:39.350: W/System.err(2785): ... 23 more

Serializablepair class

import java.io.Serializable; import android.util.Pair;

public class Serializablepair extends Pair Implements Serializable {

public SerializablePair(F first, S second) {
    super(first, second);
    // TODO Auto-generated constructor stub
}

}

1 answer

4


Note: On Android, it is usually more practical to start the analysis of stack trace from the end going evaluating the problems until we find the last reference to "Caused By". This last reference usually points to the specific problem we are facing.

You don’t have all of Logcat’s output, but the cause of your problem seems to be:

java.io.InvalidClassException: android.util.Pair; IllegalAccessException

In short, you are trying to access a field or method not accessible in the course of a serialization or deserialization.


Decomposing the problem a little:

Illegalaccessexception

Thrown when a program Attempts to access a field or method which is not accessible from the Location Where the Reference is made.

That translated:

Launched when a program attempts to access a field or method that is not accessible from the place where the reference is made.

android.util.Pair

Container to Ease Passing Around a tuple of two Objects. This Object provides a sensible implementation of equals(), returning true if equals() is true on each of the contained Objects.

That translated:

Container to facilitate the passage around a tuple of two objects. This object provides a sensible implementation of equals(), returning true if equals() is true in each of the objects contained.

java.io.Invalidclassexception

Signals a problem During the serialization or deserialization of an Object.

That translated:

Signals a problem during serialization or deserialization of an object.

  • So @Zuul, I edited the post by placing the class he references, plus what would be the solution for him to pass the data.. I don’t understand much...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.