NoSuchElementException in FootprintsManager

I’m making a number of save calls repeatedly after one another, and when I continue a few times, I eventually see the following Exception:
AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.partyplannerlive, PID: 19417
java.util.NoSuchElementException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
at com.backendless.FootprintsManager$Inner.updateFootprintForObject(FootprintsManager.java:257)
at com.backendless.Persistence$4.handleResponse(Persistence.java:196)
at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Please provide a code snippet which we can run to see the error.

Regards,
Mark

Here are some code snippets which hopefully will help:

I invoke my call from my adapter. I have a click listener on a button inside my getView method:

@Override
public View getView(int position, View convertView, final ViewGroup parent) {
final View view = LayoutInflater.from(mContext).inflate(R.layout.content_recipe_element, parent, false);
final ImageView button = (ImageView) view.findViewById(R.id.btn_favourite);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PartyController.getInstance(mContext).saveParty(party.clone());
}
});
return view;
}

Below is PartyContoller which extends Controller, which is:

public class Controller {
protected JobManager mJobManager;
public Controller(Context context) {
Backendless.initApp(context, PartyPlannerConfig.BACKENDLESS_APP_ID,
PartyPlannerConfig.BACKENDLESS_SECRET_KEY,
context.getResources().getString(R.string.backendless_app_version));
mJobManager = PartyPlannerApplication.getInstance().getJobManager();
}
}

And here is PartyController:

public class PartyController extends Controller {
final private static String WHOAMI = "UserController";
private static PartyController instance;
public PartyController(Context context) {
super(context);
}
public synchronized static PartyController getInstance(Context context) {
if(instance == null) {
instance = new PartyController(context);
}
return instance;
}
public void getPartyList() throws UserException {
mJobManager.addJobInBackground(new GetPartyListJob());
}
public void saveParty(Party party) {
final Calendar c = Calendar.getInstance();
party.setUpdated(c.getTimeInMillis());
PartyPlannerConfig.setCurrentParty(party);
mJobManager.addJobInBackground(new SavePartyJob(party));
}
}

And here is my SavePartyJob:

public class SavePartyJob extends KellogsJob {
private static String WHOAMI = "SavePartyJob";
private Party mParty;
public SavePartyJob(Party party) {
super();
mParty = party;
}
@Override
public void onRun() throws Throwable {
Backendless.Persistence.of(Party.class).save(mParty,
new AsyncCallback<Party>() {
@Override
public void handleResponse(Party response) {
PartyPlannerLog.v(WHOAMI, "Party Saved");
EventBus.getDefault().post(new SavePartyResultEvent(response));
}
@Override
public void handleFault(BackendlessFault fault) {
PartyPlannerLog.v(WHOAMI, "Party not Saved");
EventBus.getDefault().post(new SavePartyResultEvent());
}
});
}
}

Below is SavePartyResultEvent:

public class SavePartyResultEvent {
Boolean mSuccess;
Party mParty;
public SavePartyResultEvent() {
mSuccess = false;
}
public SavePartyResultEvent(Party response) {
mParty = response;
mSuccess = true;
}
public Boolean isSuccess() {
return mSuccess;
}
public Party getParty() {
return mParty;
}
}

And finally, below is Party.java:

public class Party extends ModelObject {
private ColorScheme colorScheme;
private String decourColorStyle;
private Long endTime;
private Object guests;
private int meetingID;
private List<Recipe> menuItems = new ArrayList<>();
private Moodboard moodboard;
private MusicPlaylist musicPlaylist;
private String name;
private String notes;
private Occasion occasion;
private Occasion placecard;
private Occasion plannerNotes;
private List<ShoppingListItem> shoppingList = new ArrayList<>();
private Long startTime;
private String style;
private String theme;
private String type;
private Object userImagesURL;
}
public List<ShoppingListItem> getShoppingList() {
return shoppingList;
}
public void setShoppingList(List<ShoppingListItem> shoppingList) {
this.shoppingList = shoppingList;
}
public String getDecourColorStyle() {
return decourColorStyle;
}
public Long getStartTime() {
return startTime;
}
public Long getEndTime() {
return endTime;
}
public String getName() {
return name;
}
public Occasion getOccasion() {
return occasion;
}
public String getStyle() {
return style;
}
public String getTheme() {
return theme;
}
public Moodboard getMoodboard() {
return moodboard;
}
public ColorScheme getColorScheme() {
return colorScheme;
}
public void setColorScheme(ColorScheme colorScheme) {
this.colorScheme = colorScheme;
}
public void setDecourColorStyle(String decourColorStyle) {
this.decourColorStyle = decourColorStyle;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public void setName(String name) {
this.name = name;
}
public void setOccasion(Occasion occassion) {
this.occasion = occassion;
}
public void setStyle(String style) {
this.style = style;
}
public void setTheme(String theme) {
this.theme = theme;
}
public void setMoodboard(Moodboard moodboard) {
this.moodboard = moodboard;
}
public MusicPlaylist getMusicPlaylist() {
return musicPlaylist;
}
public void setMusicPlaylist(MusicPlaylist musicPlaylist) {
this.musicPlaylist = musicPlaylist;
}
public List<Recipe> getMenuItems() {
return menuItems == null ? new ArrayList<Recipe>() : menuItems;
}
public void setMenuItems(List<Recipe> menuItems) {
this.menuItems = new ArrayList<>(menuItems);
}
public Party clone() {
final Party party = new Party();
party.setObjectId(this.getObjectId());
party.setOwnerId(this.getOwnerId());
party.setCreated(this.getCreated());
party.setUpdated(this.getUpdated());
party.setDecourColorStyle(this.getDecourColorStyle());
party.setStartTime(this.getStartTime());
party.setEndTime(this.getEndTime());
party.setName(this.getName());
party.setStyle(this.getStyle());
party.setTheme(this.getTheme());
party.setOccasion(this.getOccasion());
party.setMoodboard(this.getMoodboard());
party.setColorScheme(this.getColorScheme());
party.setMusicPlaylist(this.getMusicPlaylist());
party.setMenuItems(this.getMenuItems());
party.setShoppingList(this.getShoppingList());
return party;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Party)) return false;
Party party = (Party) o;
return Objects.equals(getDecourColorStyle(), party.getDecourColorStyle()) &&
Objects.equals(getStartTime(), party.getStartTime()) &&
Objects.equals(getEndTime(), party.getEndTime()) &&
Objects.equals(getName(), party.getName()) &&
Objects.equals(getStyle(), party.getStyle()) &&
Objects.equals(getTheme(), party.getTheme()) &&
Objects.equals(getOccasion(), party.getOccasion()) &&
Objects.equals(getMoodboard(), party.getMoodboard()) &&
Objects.equals(getColorScheme(), party.getColorScheme()) &&
Objects.equals(getMusicPlaylist(), party.getMusicPlaylist()) &&
Objects.equals(getMenuItems(), party.getMenuItems()) &&
Objects.equals(getShoppingList(), party.getShoppingList());
}
@Override
public int hashCode() {
return Objects.hash(getDecourColorStyle(), getStartTime(), getEndTime(), getName(), getStyle(), getTheme(), getOccasion(), getMoodboard(), getColorScheme(), getMusicPlaylist(), getMenuItems(), getShoppingList());
}
}

Hello @Yusuf,

Could you please compile new project reproducing this specific problem and also provide us data export. Please send the project and data export to support@backendless.com.
Artur

Hi Yusuf,

Thanks for sharing the code. To reproduce the problem, we would need a full closure of the Party class. That means would need to have all the classes to get Party to compile. Could you please create a zip file and upload to either google drive or dropbox and email the link to support@backendless.com?

Regards,
Mark

Hey there, I seem to be having the same issue here. I’m trying to update something over and over again. Basically I’m sending a train of updates to that one object, but the update fails at some point with that aforementioned exception.

What should one do here?

Salman,

Does your code happen to modify the object on the client while it is “in transit” to the server?

Mark

The request are made through async calls, so I guess some request are being sent out while the previous request is still taking place.

How do I handle this?

You could try making a copy of the object you sent out and on work on a copy instead.