-1

I want to fetch image from table 1 to update image in table 2 on parse here is my code

 ParseFile image= ParseUser.getCurrentUser().getParseFile("image");

    if(image==null)
    {

    }
    else
    {
        try {
            byte[] data=image.getData();


            Bitmap bmp = BitmapFactory
                  .decodeByteArray(
                          data, 0,
                          data.length);


          // Set the Bitmap into the
          // ImageView
          image1.setImageBitmap(bmp);




        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

This code is working perfect it retrieves and set image properly now I want this "image" to upload in my Second table I am doing this

ParseQuery<ParseObject> query = ParseQuery.getQuery("XYZ");
          String user_id=ParseUser.getCurrentUser().getObjectId();
        query.getInBackground(user_id, new GetCallback<ParseObject>() {

            @Override
            public void done(ParseObject pdata, ParseException e) {
                // TODO Auto-generated method stub

                pdata.put("image",image); // this line throw NullPointerException
                pdata.saveInBackground();
            }
        });

What I am doing wrong anyone please help?

John
  • 15
  • 1
  • 6

1 Answers1

0

You need ParseFile object. Try the following code. (It works fine, I just checked it)

               byte[] pfArray = getBytesFromBitmap(bmp);
                ParseFile file = new ParseFile("abc.png", pfArray);
                // Upload the image into Parse Cloud
                file.saveInBackground(new SaveCallback() {

                    @Override
                    public void done(ParseException e) {
                        System.out.println("saved");

                    }
                });

public byte[] getBytesFromBitmap(Bitmap bitmap) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.PNG, 70, stream);
        return stream.toByteArray();
    }

hope it helps.

Tushar Gogna
  • 4,963
  • 6
  • 31
  • 42
  • Bitmap image=BitmapFactory.decodeFile(path); i am asking about this path – John Nov 17 '14 at 12:10
  • If you're getting the bitmap then just pass it. Understand the code before down voting. – Tushar Gogna Nov 17 '14 at 12:13
  • byte[] pfArray = getBytesFromBitmap(bmp); <- use this! – Tushar Gogna Nov 17 '14 at 12:14
  • getBytesFromBitmap is not builtin method – John Nov 17 '14 at 12:19
  • String user_id=ParseUser.getCurrentUser().getObjectId(); ParseQuery query = ParseQuery.getQuery("Create_Meetup"); query.whereEqualTo("Userid", user_id); query.getInBackground(user_id, new GetCallback() { @Override public void done(ParseObject pdata, ParseException e) { // TODO Auto-generated method stub byte[] pfArray = getBytesFromBitmap(bmp); ParseFile file = new ParseFile("img.txt", pfArray); pdata.put("image",file); pdata.saveInBackground(); } }); doing this and got the same exception – John Nov 17 '14 at 12:30
  • Use some sort of validation for your own good.. In done: public void done(ParseObject pdata, ParseException e) { if(pdata==null){}else{ that code } – Tushar Gogna Nov 17 '14 at 12:36
  • in my logcat it show value "com.parse.ParseFile@42ebb0b0" but at this line pdata.put("image",file); its throws NullPointerException :( – John Nov 17 '14 at 12:55
  • `com.parse.ParseFile@42ebb0b0` is the object not the file. – Tushar Gogna Jan 08 '15 at 10:40