Comments (8)
@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.
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.
And no I'm not using proguard
from parceler.
@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.
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.
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.
@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.
Problem solved! 👍
from parceler.
Related Issues (20)
- Ability to treat reflection warnings as errors HOT 5
- Parceler fails when used with with Lifecycle-viewmodel 2.2.0 HOT 7
- Facing Vulnerabilities in parceler library HOT 1
- Facing Vulnerabilities in parceler library HOT 1
- Polymorphism documentation not updated? HOT 6
- Cannot get working with navigation graph HOT 1
- Crashing on background HOT 4
- ParcelAnnotationProcessor.process take lot amount of time. HOT 15
- Unable to find generated Parcelable class HOT 1
- error: Parceler: Code generation did not complete successfully. HOT 47
- Cant find class to parcel ! HOT 1
- Can't generate code HOT 3
- Unable to Marshall with Parceler HOT 2
- Errors in HashMap$$PackageHelper HOT 3
- cannot running with kapt HOT 1
- Parceler: Code generation did not complete successfully. org.parceler.transfuse.transaction.TransactionRuntimeException: Encountered ErrorType <error>, unable to recover HOT 4
- [Request Feature] Support for Kotlin Symbol Processing
- Parceler code generation fails on AS 2023.3.1
- Getters and Setter Alphabetically Order for Write and Read
- Not sure how to convert a Cursor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parceler.