使用Parceler与android

时间:2015-07-30 14:35:21

标签: android parceler

我正在尝试使用Parceler库来安卓android。到目前为止,我只使用文档中的普通样本只有一个相同的错误。

@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; }
}

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

崩溃
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)

我想念什么?

3 个答案:

答案 0 :(得分:2)

听起来好像注释处理器没有运行或配置错误。如果您使用Gradle构建以及处理器和api库的单独范围,我建议使用annotationProcessor范围:

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

请参阅网站的Getting Parceler部分了解最新信息。

答案 1 :(得分:2)

在较新版本中,您只需更新Gradle文件中的以下依赖项:

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

答案 2 :(得分:0)

错误是因为注释。它的工作原理是在build.gradle中实现

annotationProcessor 'org.parceler:parceler:1.1.9'