我在我的Android应用上使用了Realm,但我发现了一个奇怪的错误:
错误:任务':app:transformClassesWithRealmTransformerForDebug'执行失败。 javassist.CannotCompileException:setValues(Ljava / lang / String;)v in it.finproductions.discogsmanager.Structures.Collection:无法解析类型
我的收藏课是这样的:
public class Collection extends RealmObject {
private int Discogsid;
private int Folder;
// String json;
private boolean Checked = false;
private String Artist;
private String Title;
private int Year;
private int Instanceid;
private String Format;
private String Cat;
private String Thumb;
// DateTime dateadded;
private long Timestamp;
private String Tostringsearch;
private RealmList<Artists> Artists = new RealmList<>();
private RealmList<Formats> Formats = new RealmList<>();
private RealmList<Labels> Labels = new RealmList<>();
private boolean Values = false;
private boolean ToStringSearch = false;
public Collection() {
}
public Collection(int discogsid, int folder, String json) {
this.Discogsid = discogsid;
this.Folder = folder;
// this.json = json;
setValues(json);
}
public void setValues(String json) {
JSONObject row;
try {
row = new JSONObject(json);
try {
ArrayList<String> artisti = new ArrayList<>();
for (ArtistTrack a : Utils.getArtistsFromTrack(row.getJSONObject("basic_information")))
artisti.add(a.getName());
Artist = TextUtils.join(", ", artisti);
JSONArray elencoArtisti = row.getJSONObject("basic_information").getJSONArray("artists");
for (int i = 0; i < elencoArtisti.length(); i++) {
Artists.add(new Artists(
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "join"),
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "name"),
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "anv"),
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "tracks"),
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "role"),
Utils.takeJsonString(elencoArtisti.getJSONObject(i), "resource_url"),
Utils.takeJsonInt(elencoArtisti.getJSONObject(i), "join")
));
}
} catch (Exception e) {
Artist = "";
}
try {
Title = row.getJSONObject("basic_information").getString("title");
} catch (Exception e) {
Title = "";
}
try {
Year = row.getJSONObject("basic_information").getInt("year");
} catch (Exception e) {
Year = 0;
}
try {
Instanceid = row.getInt("instance_id");
} catch (Exception e) {
Instanceid = 0;
}
try {
Format = TextUtils.join(Utils.DIVISORFORLISTINDB, Utils.iterateEveryValueInArrayListForFormat(row.getJSONObject("basic_information"), "formats"));
JSONArray elencoFormats = row.getJSONObject("basic_information").getJSONArray("formats");
for (int i = 0; i < elencoFormats.length(); i++) {
RealmList<Descriptions> descrizione = new RealmList<>();
for (int ii = 0; ii < elencoFormats.getJSONObject(i).getJSONArray("descriptions").length(); ii++) {
descrizione.add(new Descriptions(elencoFormats.getJSONObject(i).getJSONArray("descriptions").getString(ii)));
}
Formats.add(new Formats(
Utils.takeJsonString(elencoFormats.getJSONObject(i), "name"),
Utils.takeJsonString(elencoFormats.getJSONObject(i), "qty"),
descrizione
));
}
} catch (Exception e) {
Format = "";
}
try {
Cat = TextUtils.join(Utils.DIVISORFORLISTINDB, Utils.iterateEveryValueInArrayListForLabel(row.getJSONObject("basic_information"), "labels"));
JSONArray elencoLabels = row.getJSONObject("basic_information").getJSONArray("artists");
for (int i = 0; i < elencoLabels.length(); i++) {
Labels.add(new Labels(
Utils.takeJsonString(elencoLabels.getJSONObject(i), "name"),
Utils.takeJsonString(elencoLabels.getJSONObject(i), "entity_type"),
Utils.takeJsonString(elencoLabels.getJSONObject(i), "catno"),
Utils.takeJsonString(elencoLabels.getJSONObject(i), "resource_url"),
Utils.takeJsonInt(elencoLabels.getJSONObject(i), "id"),
Utils.takeJsonString(elencoLabels.getJSONObject(i), "entity_type_name")
));
}
} catch (Exception e) {
System.out.println("NO CAT");
Cat = "";
}
try {
Thumb = row.getJSONObject("basic_information").getString("thumb");
if (Thumb.equals("")) {
Thumb = Utils.DEFAULT_RELEASE;
}
} catch (Exception e) {
Thumb = Utils.DEFAULT_RELEASE;
}
try {
DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-DDThh:mm:ssTZD");
Timestamp = new Timestamp(formatter.parseDateTime(row.getString("date_added")).getMillis()).getTime();
} catch (Exception e) {
}
Tostringsearch = getArtist() + " " + getTitle() + " " + TextUtils.join(" ", getFormat()) + " " + TextUtils.join(" ", getCat()) + " " + getYear();
Tostringsearch = Tostringsearch.toLowerCase();
} catch (Exception e) {
} }
public boolean isToStringSearch() {
return ToStringSearch;
}
public void setToStringSearch(boolean toStringSearch) {
ToStringSearch = toStringSearch;
}
public int getDiscogsid() {
return Discogsid;
}
public void setDiscogsid(int discogsid) {
Discogsid = discogsid;
}
public int getFolder() {
return Folder;
}
public void setFolder(int folder) {
Folder = folder;
}
public String getArtist() {
return Artist;
}
public void setArtist(String artist) {
Artist = artist;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public int getYear() {
return Year;
}
public void setYear(int year) {
Year = year;
}
public int getInstanceid() {
return Instanceid;
}
public void setInstanceid(int instanceid) {
Instanceid = instanceid;
}
public void setFormat(String format) {
Format = format;
}
public void setCat(String cat) {
Cat = cat;
}
public String getThumb() {
return Thumb;
}
public void setThumb(String thumb) {
Thumb = thumb;
}
public void setTimestamp(long timestamp) {
Timestamp = timestamp;
}
public String getTostringsearch() {
return Tostringsearch;
}
public void setTostringsearch(String tostringsearch) {
Tostringsearch = tostringsearch;
}
public RealmList<it.finproductions.discogsmanager.Structures.Artists> getArtists() {
return Artists;
}
public void setArtists(RealmList<it.finproductions.discogsmanager.Structures.Artists> artists) {
Artists = artists;
}
public RealmList<it.finproductions.discogsmanager.Structures.Formats> getFormats() {
return Formats;
}
public void setFormats(RealmList<it.finproductions.discogsmanager.Structures.Formats> formats) {
Formats = formats;
}
public RealmList<it.finproductions.discogsmanager.Structures.Labels> getLabels() {
return Labels;
}
public void setLabels(RealmList<it.finproductions.discogsmanager.Structures.Labels> labels) {
Labels = labels;
}
public boolean isValues() {
return Values;
}
public void setValues(boolean values) {
Values = values;
}
public List<String> getFormat() {
// return format;
return new ArrayList<>(Arrays.asList(Format.split(Utils.DIVISORFORLISTINDB)));
}
public List<String> getCat() {
// return cat;
return new ArrayList<>(Arrays.asList(Cat.split(Utils.DIVISORFORLISTINDB)));
}
public Date getTimestamp() {
return new Date(Timestamp);
}
// public String toStringExpectJson() {
// return "TSEJ: " + Discogsid + ", " + Folder + ", " + getArtist() + ", " + getTitle() + ", " + getYear() + getInstanceid();
// }
public String getToStringSearch() {
return getArtist() + " " + getTitle() + " " + getFormat() + " " + getCat() + " " + getYear();
}
public void setChecked(boolean set) {
Checked = set;
}
public boolean getChecked() {
return Checked;
}
}
艺术家,格式和标签是扩展RealmObject的其他类。
我试图重建项目,但没有任何改变......
我的项目构建是:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
classpath "io.realm:realm-gradle-plugin:0.88.3"
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的app app gradle以
开头apply plugin: 'android'
apply plugin: 'realm-android'
有人可以弄清楚问题是什么?
编辑1: 添加了整个setValues()方法。
编辑2: 其他被称为方法的是:
public class Artists extends RealmObject {
private String join;
private String name;
private String anv;
private String tracks;
private String role;
private String resource_url;
private int id;
public Artists() {
}
public Artists(String join, String name, String anv, String tracks, String role, String resource_url, int id) {
this.join = join;
this.name = name;
this.anv = anv;
this.tracks = tracks;
this.role = role;
this.resource_url = resource_url;
this.id = id;
}
public String getJoin() {
return join;
}
public void setJoin(String join) {
this.join = join;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAnv() {
return anv;
}
public void setAnv(String anv) {
this.anv = anv;
}
public String getTracks() {
return tracks;
}
public void setTracks(String tracks) {
this.tracks = tracks;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getResource_url() {
return resource_url;
}
public void setResource_url(String resource_url) {
this.resource_url = resource_url;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
public class Artists extends RealmObject {
private String join;
private String name;
private String anv;
private String tracks;
private String role;
private String resource_url;
private int id;
public Artists() {
}
public Artists(String join, String name, String anv, String tracks, String role, String resource_url, int id) {
this.join = join;
this.name = name;
this.anv = anv;
this.tracks = tracks;
this.role = role;
this.resource_url = resource_url;
this.id = id;
}
public String getJoin() {
return join;
}
public void setJoin(String join) {
this.join = join;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAnv() {
return anv;
}
public void setAnv(String anv) {
this.anv = anv;
}
public String getTracks() {
return tracks;
}
public void setTracks(String tracks) {
this.tracks = tracks;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getResource_url() {
return resource_url;
}
public void setResource_url(String resource_url) {
this.resource_url = resource_url;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
public class Labels extends RealmObject {
private String name;
private String entity_type;
private String catno;
private String resource_url;
private int id;
private String entity_type_name;
public Labels() {
}
public Labels(String name, String entity_type, String catno, String resource_url, int id, String entity_type_name) {
this.name = name;
this.entity_type = entity_type;
this.catno = catno;
this.resource_url = resource_url;
this.id = id;
this.entity_type_name = entity_type_name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEntity_type() {
return entity_type;
}
public void setEntity_type(String entity_type) {
this.entity_type = entity_type;
}
public String getCatno() {
return catno;
}
public void setCatno(String catno) {
this.catno = catno;
}
public String getResource_url() {
return resource_url;
}
public void setResource_url(String resource_url) {
this.resource_url = resource_url;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEntity_type_name() {
return entity_type_name;
}
public void setEntity_type_name(String entity_type_name) {
this.entity_type_name = entity_type_name;
}
}