gpt4 book ai didi

java - GreenDAO 3.1.1 注释处理在 "[Type] cannot be resolved to a variable"处失败

转载 作者:行者123 更新时间:2023-12-01 09:30:50 25 4
gpt4 key购买 nike

任何帮助或指导都会很棒;我最近开始使用 GreenDAO(版本 3.1.1),使用他们的新注释处理器,而不是像以前的版本那样使用生成项目。

一切都很顺利,直到我尝试添加带有类类型参数的自定义构造函数,或者引用类中的其他类类型函数。

我遇到了以下错误:

Found 1 problem(s) parsing "C:\~\authentication\providers\AuthenticationToken.java":
Pb(83) AuthenticationProviderTypes cannot be resolved to a variable
:jroot:greendao FAILED

我正在使用:

- GreenDAO 3.1.1
- Android Studio 2.1.3
- buildToolsVersion 23.0.3
- targetCompatibility JavaVersion.VERSION_1_7
- compileSdkVersion/targetSdkVersion 24
- minSdkVersion 19

我尝试过的:

- Invalidate cache / restart android studio
- Clean build (like infinity times)
- Removing the custom constructor
- Does build, but defeats the point of needing constructor.
- Read through the documentation and added the @Keep annotation.

这是我的实体类的简短示例:

@Entity(nameInDb = "authentication_token", active = true, createInDb = true)
public final class AuthenticationToken implements Serializable {
@Unique
@Id(autoincrement = false)
private Long id;

@SerializedName("InstanceAuthenticationType")
@Convert(converter = AuthenticationProviderTypes.AuthenticationProviderTypeConverter.class, columnType = Integer.class)
private AuthenticationProviderTypes authenticationType;

@SerializedName("CustomerCode")
@Convert(converter = CustomerCode.CustomerCodeConverter.class, columnType = String.class)
private CustomerCode customerCode;

@SerializedName("ContactCode")
@Convert(converter = ContactCode.ContactCodeConverter.class, columnType = String.class)
private ContactCode contactCode;

@SerializedName("PortalID")
private Integer portalID;

@Generated(hash = 1522783431)
public AuthenticationToken(Long id,
AuthenticationProviderTypes authenticationType,
CustomerCode customerCode,
ContactCode contactCode,
Integer portalID) {
// generated constructor code; this is fine, works & builds like a champ!
}

@Keep
public AuthenticationToken(AuthenticationProviderTypes preferredProviderType) {
// After successful build without this constructor
// I add this constructor to the entity class
// and it causes the GreenDAO generator / build to fail.
// without any other changes to the class or code
authenticationType = preferredProviderType;
}
}

更新:我想知道这个问题是限制还是错误。我删除了自定义构造函数,从生成的空构造函数创建了类实例,并使用生成的 setter 设置了变量。它有效,但违背了在对象逻辑中拥有具体构造函数的观点。我觉得这表明生成器知道并可以解析我的 AuthenticationProviderTypes 类,只是不是在构造函数级别。

再次感谢您的帮助或建议。

最佳答案

让 GreenDao 生成它的方法..然后实现可序列化或可打包。

我删除所有生成的方法,然后调用

./gradlew greendao

关于java - GreenDAO 3.1.1 注释处理在 "[Type] cannot be resolved to a variable"处失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39418023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com