Git Product home page Git Product logo

Comments (8)

johncarl81 avatar johncarl81 commented on August 10, 2024

@tom91136, can you verify you're using the same version between the parceler and parceler-api dependencies? Also, can you verify that NonParcelRepository exists in the parceler-api library with the MapParcelable inner class?

Are you using proguard by chance?

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

I'm using 0.2.11 snapshot and the versions match; all the classes you
mentioned are there(otherwise it would probably have failed earlier because
of the HashMap in MyData class )
On Aug 14, 2014 4:37 AM, "John Ericksen" [email protected] wrote:

@tom91136 https://github.com/tom91136, can you verify you're using the
same version between the parceler and parceler-api dependencies? Also, can
you verify that NonParcelRepository exsists in the parceler-api library
with the MapParcelable inner class?

Are you using proguard by chance?


Reply to this email directly or view it on GitHub
#40 (comment).

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

And no I'm not using proguard

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

@tom91136, I tend to agree with you, this has something to do with the Parcelable object classloader. Im attempting to recreate this problem now. Is there any way you can share a sample project demonstrating this?

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

A self contained example with 2 activities only:
TestActivity creates all the data and passes it to MyActivity2 using an Intent; MyActivity2 reads it and crashes

TestActivity.java

public class TestActivity extends Activity {

    private static final String TAG = "TestActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        Bundle bundle = new Bundle();
        HashMap<String, String> map = new HashMap<>();
        map.put("a", "b");
        bundle.putParcelable("foo", Parcels.wrap(map));
        bundle.putInt("foo1", 42);

        MyData myData = new MyData();
        myData.nodes.put("bar", bundle);

        Intent intent = new Intent(this, MyActivity2.class);
        intent.putExtra("key", Parcels.wrap(myData));
        startActivity(intent);

    }

    @Parcel
    public static class MyData {
        public HashMap<String, Bundle> nodes = new HashMap<>();
    }

}

And MainActivity2.java

public class MyActivity2 extends Activity {

    private static final String TAG = "MyActivity2";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_activity2);

        Intent intent = getIntent();
        MyData data = Parcels.unwrap(intent.getParcelableExtra("key"));

        Bundle bundle2 = data.nodes.get("bar");
        int myInt = bundle2.getInt("foo1"); // works
        Log.d(TAG, "myInt:" + myInt);
        HashMap<String, String> map2 = Parcels.unwrap(bundle2.getParcelable("foo")); // fails
        Log.d(TAG, "map:" + map2); // never reached 

    }
}

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

The reason why I used two activities is because if you don't pass to another activity, it won't crash

Here's an example of not passing it across another activity:

    @Ovrride
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        Bundle bundle = new Bundle();
        HashMap<String, String> map = new HashMap<>();
        map.put("a", "b");
        bundle.putParcelable("foo", Parcels.wrap(map));
        bundle.putInt("foo1", 42);

        MyData myData = new MyData();
        myData.nodes.put("bar", bundle);

        Intent intent = new Intent(this, MyActivity2.class);
        intent.putExtra("key", Parcels.wrap(myData));
        //startActivity(intent);

        readStuff(intent);

    }



    private void readStuff(Intent intent){

        MyData data = Parcels.unwrap(intent.getParcelableExtra("key"));
        Bundle bundle2 = data.nodes.get("bar");
        int myInt = bundle2.getInt("foo1"); // works
        Log.d(TAG, "myInt:" + myInt);
        HashMap<String, String> map2 = Parcels.unwrap(bundle2.getParcelable("foo")); // fails
        Log.d(TAG, "map:" + map2); // never reached
    }

And the log outputs are:

08-14 06:02:05.209    2260-2260/playground.sora.com.playground D/TestActivity﹕ myInt:42
08-14 06:02:05.209    2260-2260/playground.sora.com.playground D/TestActivity﹕ map:{a=b}

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

@tom91136, thanks for the examples, that helped a lot. It seems the problem was related to the classloader used within the Bundle. The fix was to supply a classloader to the readBundle() method. You can find the fix under 0.2.11-SNAPSHOT on Maven central or here: 5ba9269 Let me know if this fixes the problem for you.

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

Problem solved! 👍

from parceler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.