我有两个类NewsImage
和EventImage
几乎完全相同,因此它们继承自Image
抽象类。这两个中的每一个都代表我的Parse数据库中的一个类。
public abstract class Image extends ParseObject {
public Image(){};
public String getImageId(){
return getObjectId();
}
public void setImageId(String imageId){
setObjectId(imageId);
}
public byte[] getImageBytes(){
try {
return getParseFile("image").getData();
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
public void setImageBytes(byte[] bytes){
put("image", new ParseFile(bytes));
}
public Bitmap getBitmap(){
return Toolbox.ByteArrayToBitmap(getImageBytes());
}
EventImage类
@ParseClassName("OSW_event_images")
public class EventImage extends Image {
public EventImage() {
super();
}
public Event getEvent(){
return (Event) getParseObject("event");
}
public void setEvent(Event event){
put("event", event);
}
};
NewsImage类
@ParseClassName("OSW_news_images")
public class NewsImage extends Image {
public NewsImage() {
super();
}
public News getNews(){
return (News) getParseObject("news");
}
public void setNews(News event){
put("news", event);
}
};
}
我在致电Parse.initialize()
ParseObject.registerSubclass(Image.EventImage.class);
ParseObject.registerSubclass(Image.NewsImage.class);
我跑完之后得到:
09-19 12:38:39.794: E/AndroidRuntime(25806): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.holdapp.osw/pl.holdapp.osw.activities.MainActivity}: java.lang.IllegalArgumentException: No default constructor provided for class pl.holdapp.osw.objects.Image$EventImage
09-19 12:38:39.794: E/AndroidRuntime(25806): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
答案 0 :(得分:2)
使EventImage类成为静态。现在,默认构造函数需要对外部类的隐式引用。