0

I have Array of files (images) at localdataStore of parse.com and I want to fetch file from there, I have implemented following code...

 ParseQuery<ParseObject> query = ParseQuery.getQuery("Test_class");

query.whereEqualTo("objectId", "SSDW232sda");
query.fromLocalDatastore();

    try{
        List<ParseObject> objects = queryChild.find();
        System.out.println(objects.size());
        ParseObject object = objects.get(0);


        JSONArray imagesArr = object.getJSONArray("images");

        for(int i=0;i<imagesArr.length();i++){
            try {
                ParseFile image =  (ParseFile) imagesArr.getJSONObject(i).get("name");//.getParseFile("name");
                byte[] img = image.getData();
                bitmaps.add(BitmapFactory.decodeByteArray(img , 0, img.length));
            } catch (ParseException e1) {
                e1.printStackTrace();
                System.out.println("could not get image");
            }
        }


    }catch(Exception e) {
      e.printStackTrace();
    }

but it gives the following error

 java.lang.ClassCastException: java.lang.String cannot be cast to com.parse.ParseFile

help me to fix this problem..

Naveed Ali
  • 2,609
  • 1
  • 22
  • 37
  • the error which I mention above is log cat error... what response you are asking? – Naveed Ali May 08 '14 at 11:57
  • You get this because imagesArr.getJSONObject(i).get("name") returns a String object. Maybe the name of the file? Do a printline on imagesArr.getJSONObject(i).get("name") to see what you get. Also, you should include the code where the image array is written to localdatastore – Marius Waldal May 08 '14 at 11:57

1 Answers1

1

Here's the spec for JSON. There isn't a ParseFile object in there.

You probably want to get the String from JSON, convert it into a byte array, then call the ParseFile constructor.

Ex.

String stringFromJson = json.getString("whatever_key_you_need");
byte[] stringFromJsonAsByteArray = stringFromJson.getBytes();

ParseFile parseFile = new ParseFile("filename.txt", stringFromJsonAsByteArray);
Justin Jasmann
  • 2,363
  • 2
  • 14
  • 18