0

I have two classes NewsImage and EventImage that are almost identical and therefore they inherit from Image abstract class. Each of those two represent a class in my Parse database.

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 Class

    @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 class

    @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);
        }

    };

}

I register those two classes before I call Parse.initialize()

ParseObject.registerSubclass(Image.EventImage.class);
ParseObject.registerSubclass(Image.NewsImage.class);

After I run this I get:

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
  • 1
    problem is that EventImage is not static nested class... it cannot exists without outer Image class instance ... pl.holdapp.osw.objects.Image$EventImage Commented Sep 19, 2014 at 10:48

1 Answer 1

2

Make the EventImage class static. As it is now the default constructor needs an implicit reference to the outer class.

Sign up to request clarification or add additional context in comments.

1 Comment

Eventually, I put them both out of my abstract Image class but you are certainly right that those classes cannot exist without Image being instantiated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.