Reputation: 386
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
Upvotes: 2
Views: 4754
Reputation: 9258
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?
Upvotes: 6