例外:"没有提供默认的构造函数"异步子类化ParseObject

时间:2014-09-19 10:42:04

标签: java android oop inheritance parse-platform

我有两个类NewsImageEventImage几乎完全相同,因此它们继承自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)

1 个答案:

答案 0 :(得分:2)

使EventImage类成为静态。现在,默认构造函数需要对外部类的隐式引用。