首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Parceler -无法找到生成的Parcelable类

Parceler -无法找到生成的Parcelable类
EN

Stack Overflow用户
提问于 2017-02-22 08:41:04
回答 3查看 3.5K关注 0票数 3

编辑

在清理和重新生成类之后,将不会生成类。

我在尝试使用Parcels.wrap()时遇到了这个错误

代码语言:javascript
复制
Unable to find generated Parcelable class for xyz.xyz.models.reclamation.Reclamation, verify that your class is configured properly and that the Parcelable class xyz.xyz.models.reclamation.Reclamation$$Parcelable is generated by Parceler.

但是创建了Reclamation$$Parcelable类,我可以看到它的内容。

那是我的秤:

代码语言:javascript
复制
compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'

试图将annotationProcessor更改为apt会导致生成错误。

那是填海课

代码语言:javascript
复制
@Parcel
public class Reclamation {

public Reclamation() {
}

private int reclamationProductID;

private Integer preference;

private String takingDate1;

private String takingDate2;

private int takingAddressID;

private String takingAddressStreet;

private String takingAddressCity;

private String takingAddressZipCode;

private int type;

private String takingAddressCompany;
// + getters setters
}

那是它崩溃的地方。

代码语言:javascript
复制
ServiceStepFour_.builder().arg(Constants.ARG_RECLAMATION, Parcels.wrap(reclamation)).build();

我将它与Android注释结合使用。

有人知道为什么会这样吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-02-22 09:43:43

尽管文档中说,您必须将这些行放到gradle中:

代码语言:javascript
复制
compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'

改为:

代码语言:javascript
复制
compile 'org.parceler:parceler-api:1.1.6'
apt 'org.parceler:parceler:1.1.6'

确保要使用的所有文件都带有@Parcel注释。

我有一个带有B类变量的A类,我忘了注释B类,这就是为什么从annotationProcessor更改为apt会给我带来一个构建错误。

票数 4
EN

Stack Overflow用户

发布于 2017-03-09 20:18:33

在我的例子中,当我从apt移到时,我必须删除这一行

代码语言:javascript
复制
apply plugin: 'com.neenbedankt.android-apt'
票数 1
EN

Stack Overflow用户

发布于 2022-11-17 13:24:40

我知道这是个迟来的答案,但也许其他人稍后会有这个问题,

如果在代码中使用Kotlin,则必须使用kapt而不是annotationProcessor来解决问题。

代码语言:javascript
复制
apply plugin: 'kotlin-kapt'

dependencies {
    kapt 'org.parceler:parceler:1.1.12'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42386485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档