so I'm going to break this down as clearly as I can.
1) So I queried an array of ParseFile Images from Parse and I want to convert them into a Bitmap array. So here is the code for that.
public void queryImage() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("TestObject");
//So lets queryImage all the images that belong to the user.
query.setLimit(2);
query.whereExists("ImageFile");
query.orderByDescending("createdAt");
try {
List<ParseObject> lists2 = query.find();
for(ParseObject cardImage : lists2) {
ParseImageFileArrayList.add((ParseFile) cardImage.get("ImageFile"));
}
convertFileArray(ParseImageFileArrayList);//Here is another I created
} catch(ParseException e) {
e.printStackTrace();
}
}
2) Now in that method I called convertFileArray() method, which takes in that parsefile array and converts it into a bitmap. Here is the code for that.
private void convertFileArray(ArrayList<ParseFile> arrayList) {
for(ParseFile file: arrayList) {
if(file != null) {
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if(e == null) {
bmp1 = BitmapFactory.decodeByteArray(bytes,0,bytes.length);
BitmapArray.add(bmp1);
} else {
}
}
});
}
}
}
3) Okay, now I want to loop through a string of Names, "John, Mary, Adam, Susan, etc.) And for each name at that position I want to add the corresponding Image from the Bitmap array. So if John is at position 0 in the name Array, I should add the image at Position 0 of John from my Byte array into a class I call "CardModel" Here is the code. And mind you, these 3 methods are all in 1 class.
public void queryDoneSetCards() {//Here we need to make an Array of Cardmodels.
for(int i = 0; i < queryCardNames.size(); i++) {
CardModel cardModel = new CardModel();
cardModel.setImageAsBitmap(BitmapArray.get(i));//HERE IS WHERE IM GETTING THE ERROR!
CardModelArray.add(cardModel);
}
}
4) Finally when I get to another activity, where the user clicks "Done" (the queryImage method gets called first, which has the convertFileArray() method in it that gets called) then the queryDoneSetCards() method gets called. And I get this an index out of bounds exception I cant figure out why its not working.
Process: com.lorentzos.swipecards.example, PID: 23182
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
12-08 13:26:47.218 23182-23182/com.lorentzos.swipecards.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lorentzos.swipecards.example, PID: 23182
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at com.lorentzos.swipecards.MyParse.MyParse.queryDoneSetCards(MyParse.java:285)
at com.lorentzos.swipecards.MyParse.MyParse.convertFileArray(MyParse.java:267)
at com.lorentzos.swipecards.MyParse.MyParse.queryImage(MyParse.java:143)
at com.lorentzos.swipecards.CardFinal.Card_FINALE.onClick(Card_FINALE.java:258)
at android.view.View.performClick(View.java:4803)
at android.view.View$PerformClick.run(View.java:19981)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5430)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
queryDoneSetCards()method. Try setting some breakpoints or placing some log statements there to ensure that the queryCardNames collection has data and exists