我真的找不到问题的根源, 我以前可以构建它,而根本没有做任何更改。
这些是我遇到的两个错误: 错误:类型非法开始 错误:需要类,接口或枚举
我无法提供所有代码,但是我检查了所有代码至少50次,并且实际上无法找到问题所在。
public static final Creator<FlickrPhoto> CREATOR = new Creator<FlickrPhoto>() {
@Override
public FlickrPhoto createFromParcel(Parcel in) {
return new FlickrPhoto(in);
}
@Override
public FlickrPhoto[] newArray(int size) {
return new FlickrPhoto[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(owner);
dest.writeString(secret);
dest.writeString(server);
dest.writeString(farm);
dest.writeString(title);
dest.writeByte((byte) (isPublic ? 1 : 0));
dest.writeString(ownerName);
dest.writeString(dateAdded);
dest.writeInt(license);
dest.writeString(description);
dest.writeString(dateTaken);
dest.writeString(views);
dest.writeString(tags);
dest.writeString(placeId);
dest.writeString(media);
dest.writeString(thumb);
dest.writeString(size_n);
dest.writeString(url_n);
dest.writeString(size_z);
dest.writeString(url_z);
dest.writeString(size_c);
dest.writeString(url_c);
dest.writeString(size_l);
dest.writeString(url_l);
dest.writeString(size_h);
dest.writeString(url_h);
dest.writeString(size_k);
dest.writeString(url_k);
dest.writeString(size_o);
dest.writeString(url_o);
}
public static List<FlickrPhoto> jsonToPhotoList(String jsonString) throws JSONException {
List<FlickrPhoto> list = new ArrayList<>();
JSONObject json = new JSONObject(jsonString);
JSONObject jPhotos = json.getJSONObject("photos");
TempData.getInstance().page = JsonUtils.getInt(jPhotos, "page");
TempData.getInstance().pages = JsonUtils.getInt(jPhotos, "pages");
TempData.getInstance().perPage = JsonUtils.getInt(jPhotos, "perpage");
int total = JsonUtils.getInt(jPhotos, "total");
TempData.getInstance().total = total;
if (total > 0) {
JSONArray photoArray = jPhotos.getJSONArray("photo");
list.addAll(parsePhotoJson(photoArray.toString()));
}
return list;
}
public static List<FlickrPhoto> parsePhotoJson(String jsonString) throws JSONException {
List<FlickrPhoto> list = new ArrayList<>();
JSONArray photoArray = new JSONArray(jsonString);
for (int i = 0; i < photoArray.length(); i++) {
JSONObject j = photoArray.getJSONObject(i);
FlickrPhoto photo = new FlickrPhoto();
photo.id = JsonUtils.getLong(j, "id");
photo.owner = JsonUtils.getString(j, "owner");
photo.secret = JsonUtils.getString(j, "secret");
photo.server = JsonUtils.getString(j, "server");
photo.farm = JsonUtils.getString(j, "farm");
photo.title = JsonUtils.getString(j, "title");
photo.isPublic = JsonUtils.getBoolean(j, "ispublic");
photo.ownerName = JsonUtils.getString(j, "ownername");
/*long dateAdded = JsonUtils.getLong(j, "dateadded");
photo.dateAdded = getDateFromUnix(dateAdded); */
photo.license = JsonUtils.getInt(j, "license");
/* JSONObject description = j.getJSONObject("description");
photo.description = JsonUtils.getString(description, "_content"); */
/* String datetaken = JsonUtils.getString(j, "datetaken");
photo.dateTaken = getDateFromString(datetaken); */
//photo.views = JsonUtils.getString(j, "views");
photo.tags = JsonUtils.getString(j, "tags");
//photo.placeId = JsonUtils.getString(j, "place_id");
photo.media = JsonUtils.getString(j, "media");
photo.thumb = JsonUtils.getString(j, "url_n");
photo.url_n = JsonUtils.getString(j, "url_n");
if (j.has("width_n") && j.has("height_n"))
photo.size_n = JsonUtils.getString(j, "width_n") + " * " + JsonUtils.getString(j, "height_n");
photo.url_z = JsonUtils.getString(j, "url_z");
if (j.has("width_z") && j.has("height_z"))
photo.size_z = JsonUtils.getString(j, "width_z") + " * " + JsonUtils.getString(j, "height_z");
photo.url_c = JsonUtils.getString(j, "url_c");
if (j.has("width_c") && j.has("height_c"))
photo.size_c = JsonUtils.getString(j, "width_c") + " * " + JsonUtils.getString(j, "height_c");
photo.url_l = JsonUtils.getString(j, "url_l");
if (j.has("width_l") && j.has("height_l"))
photo.size_l = JsonUtils.getString(j, "width_l") + " * " + JsonUtils.getString(j, "height_l");
photo.url_h = JsonUtils.getString(j, "url_h");
if (j.has("width_h") && j.has("height_h"))
photo.size_h = JsonUtils.getString(j, "width_h") + " * " + JsonUtils.getString(j, "height_h");
if (j.has("width_k") && j.has("height_k"))
photo.size_k = JsonUtils.getString(j, "width_k") + " * " + JsonUtils.getString(j, "height_k");
photo.url_o = JsonUtils.getString(j, "url_o");
if (j.has("width_o") && j.has("height_o"))
photo.size_o = JsonUtils.getString(j, "width_o") + " * " + JsonUtils.getString(j, "height_o");
}
}
return list;
}
错误似乎在最后几行
}
return list;
}
}
答案 0 :(得分:0)
此行上没有开头{
:
if (j.has("width_o") && j.has("height_o"))
但是,似乎您希望在这里找到一个:
photo.size_o = JsonUtils.getString(j, "width_o") + " * " + JsonUtils.getString(j, "height_o");
}
这将导致大括号不匹配,这可能会导致各种错误,这些错误会将您指向错误的方向。
因此,您要做的是在此行中添加一个,如下所示:
if (j.has("width_o") && j.has("height_o")) {