jeudi 2 avril 2015

Getting multiple byte arrays from jsonobject error

I am having trouble getting multiple byte arrays from a jsonObject in a JsonArray. I have three images in my database on azure which are each stored as a byte array. I can successfully receive the json object and retrieve the image string which i can then successfully convert to bytes and decode. However when i try to start the next activity the next screen is blank and my device eventually tell me the app is not responding! This code works if i use one image but if i use more than that then i receive this problem. I have been trying every possible solution all morning and have not been able to figure out what is wrong. Can anyone help me please? I know it must be something small but cant see where it is.



JSONArray jArray = c.getJSONArray("Exercises");
JSONArray imgJSON = null;
for(int j = 0; j < jArray.length(); j++) {
IDexerciseTemp = jArray.getJSONObject(j).getString("IDexercise");
Name = jArray.getJSONObject(j).getString("Name");
LiftValueTemp = jArray.getJSONObject(j).getString("LiftValue");
String dateTemp = jArray.getJSONObject(j).getString("DateLogged");

JSONArray stepsArray = jArray.getJSONObject(j).getJSONArray("StepL");
for(int z = 0; z < stepsArray.length(); z++)
{
step = stepsArray.getJSONObject(z).getString("StepDes");
IDstepTemp = stepsArray.getJSONObject(z).getString("IDstep");
}
IDstep = Integer.parseInt(IDstepTemp);
s1.IDstep = IDstep;
s1.StepDes = step;
stepsList.add(s1);


This loop here is what is giving me problems!! It works if i set the condition to a < 1 but anything greater than one and then when i try to move to the next activity the next screen is blank and tells me the app is not responding!



JSONArray imageArray = jArray.getJSONObject(j).getJSONArray("ExerciseImageL");
int er = imageArray.length();

System.out.println("ER: " + er);
for(int a = 0; a < imageArray.length(); a++)
{
String imageS = imageArray.getJSONObject(a).getString("Image");
System.out.println("IMAGEs: " + imageS);
byte[] eBytes = Base64.decode(imageS.getBytes(), Base64.DEFAULT);
eImage = new ExerciseImage();
eImage.Image = eBytes.clone();
System.out.println("eImage: " + eImage.Image.toString());
exerciseImgList.add(eImage);
}

Aucun commentaire:

Enregistrer un commentaire