我正在使用RSS Feed处理新闻Android项目,我的应用程序现在可以完美地获取标题,描述,新闻时间,但我无法获得图像,它显示以下错误:
Left<L, R>(l)
这是我的代码(我的Article.java):
Right<L, R>
这是(我的Adapter.java):
java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:464)
at android.net.Uri$StringUri.<init>(Uri.java:454)
at android.net.Uri.parse(Uri.java:426)
at com.example.drmzr.myapplication.MyAdapter.onBindViewHolder(MyAdapter.java:36)
at com.example.drmzr.myapplication.MyAdapter.onBindViewHolder(MyAdapter.java:12)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5453) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5486) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4723)
这个包含上述错误的行(holder.gimage.setImageURI(Uri.parse(article.getImage()));)
这是(我的RSSParser.java):
public class Article {
String title,description,date,link,image;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
答案 0 :(得分:0)
public String getImage() {
if (description.startsWith("<a ")) {
String cleanUrl = description.substring(description.indexOf("src=") + 5, description.indexOf("/>") - 2);
return cleanUrl;
} else {
return image;
}
}