2

Again having issues with Parse.com clearly I'm having issues with it. Once again it works perfectly in iOS but when I try to do the same thing in Android it fails. Error is: "Caused by: java.lang.NullPointerException" which calls this line of code "fileObject.getDataInBackground(new GetDataCallback()"

Basically, I'm trying to pull a specific image out of a parse.com table and display it within a ImageView. I have it working locally in other words I can call the image directly from the device. But this defeats the purpose of pulling the image from Parse.com.

I have followed the example provided on Parse.com website but clearly I'm not the only one having issues. https://parse.com/docs/android_guide#files

Below is my code located on the onCreate function;

ParseObject parseObject = new ParseObject("Birds");
ParseFile fileObject = (ParseFile) parseObject.get("totemImage");
fileObject.getDataInBackground(new GetDataCallback() {
    @Override
    public void done(byte[] data, ParseException e) {

        if (e == null)
        {
            Bitmap bmp = BitmapFactory .decodeByteArray(data, 0, data.length);
            ImageView pic;

            pic = (ImageView) findViewById(R.id.totemView);
            pic.setImageBitmap(bmp);

        }
        else
        {


        }

    }
}); 

Any ideas on how to fix this would be great. BTW (Birds is the table/classname in parse)

Regards, Jeremy

1 Answer 1

6

The first line of your code is creating a new ParseObject of classname Birds:

ParseObject parseObject = new ParseObject("Birds");

Then, in the very next line, you're reading the value of it's "totemImage" key:

ParseFile fileObject = (ParseFile) parseObject.get("totemImage");

Since this is a new object, it's expected that none of its keys will have any values, and as such the fileObject ParseFile is null.

Are you sure you did not mean to query for an existing object instead?

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

4 Comments

Hi Hector, Um...I think the answer here is yes. The example giving on the parse site doesn't show that "ParseObject parseObject = new ParseObject("Birds");" I assumed it was like query an object I had to specify the TableName/Class name then say which image column I want back. Furthermore I would think I would need to specify the exact row as well. Is this the correct line of thinking? or should I remove ParseObject line all together.
Or should I be getting it from another query I'm doing further up which already has those parameters i.e. specific row and content and then just ask for the image?
Got it Hector! Rather then have two queries use the same one then just reference it. Derr. It was far easier that way!
@TusharGogna, All good. What Hector suggested above allowed me to use one query to get the image out of the field. I don't really understand how you are putting an image in a users field. I kept both the users details and images separate through different columns. Perhaps put up an example of the issue so we can look at it. In the end, I had to leave Parse because of their pricing model. HTH.

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.