Using Parceler with android
Asked Answered
M

3

6

I'm trying Parceler library for android. So far I've had only one same error, using plain sample from the documentation.

@Parcel(Parcel.Serialization.BEAN)
public class Example {
  private String name;
  private int age;

  public String getName() { return name; }
  public void setName(String name) { this.name = name; }

  public int getAge() { return age; }
  public void setAge(int age) { this.age = age; }
}

And

Parcelable p = Parcels.wrap(new Example());

Which crashes with

07-30 12:31:46.439: E/AndroidRuntime(4945): FATAL EXCEPTION: main
07-30 12:31:46.439: E/AndroidRuntime(4945): Process: com.sample.app.android.debug, PID: 4945
07-30 12:31:46.439: E/AndroidRuntime(4945):  org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable  class for com.sample.app.android.entity.Example, verify that  your class is configured properly and that the Parcelable class  com.sample.app.android.entity.Example$$Parcelable is generated  by Parceler.
07-30 12:31:46.439: E/AndroidRuntime(4945):     at  org.parceler.Parcels$ParcelCodeRepository.get(Parcels.java:201)
07-30 12:31:46.439: E/AndroidRuntime(4945):     at org.parceler.Parcels.wrap(Parcels.java:85)
07-30 12:31:46.439: E/AndroidRuntime(4945):     at org.parceler.Parcels.wrap(Parcels.java:69)

What do I miss?

Moule answered 30/7, 2015 at 14:35 Comment(2)
Where do you actually set using the setter method?Lithea
@Lithea I found the problem, actually. Installation was incomplete, although it was not clear. Will post the answer soon.Moule
Q
2

It sounds like the annotation processor isn't running or is misconfigured. I'd recommend using the annotationProcessor scope if you're using a Gradle build along with separate scopes for the processor and api libraries:

compile 'org.parceler:parceler-api:1.1.9'
annotationProcessor 'org.parceler:parceler:1.1.9'

See the Getting Parceler section of the website for the latest.

Quasijudicial answered 4/8, 2015 at 0:42 Comment(0)
K
2

In the newer version, you only have to update the following dependencies in your Gradle file:

compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6' 
Kulturkampf answered 15/3, 2017 at 18:35 Comment(0)
F
0

The error is because of annotation. it works by implementing in build.gradle

annotationProcessor 'org.parceler:parceler:1.1.9'    
Foldboat answered 27/11, 2017 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.