Backendless Support
 
Answered

NoSuchElementException- Application crashed

Hi, I'm updating a list of a table's objects, At First, It worked fine for like 4-5 time then it stops working. It gives an error "java.util.NoSuchElementException - at java.util.AbstractList$SimpleListIterator.next",

It saves the object in database but aso gave the error,

kindly help me,

Here is my code for updating

  1. final HelpComments comments = new HelpComments();

    comments.setMessage(inputText.toString());

    comments.setCreator(currentUser);

    Backendless.Data.of(HelpComments.class).save(comments, new AsyncCallback<HelpComments>() {

    @Override

    public void handleResponse(HelpComments comment) {

    currentthread.addComment(comment);

    Log.d("time:",comment.getCreatedAt().toString());

    Backendless.Data.of(CommentThreads.class).save(currentthread, new AsyncCallback<CommentThreads>() {

    @Override

    public void handleResponse(CommentThreads response) {

    makeToast(inputText.toString());

    makeToast("Message Sent!");

    }

    @Override

    public void handleFault(BackendlessFault fault) {

    makeToast("Error! Failed to send!");

    Log.d("error:",fault.getMessage()+"\nError! Failed to send!\n"+fault.getDetail());

    }

    });

    }

    @Override

    public void handleFault(BackendlessFault fault) {

    makeToast("Error! Failed to send!");

    }

    });

And here is the error

  1. Process: com.example.mubtadanaqvi.stunexus, PID: 27815
  2. java.util.NoSuchElementException
  3. at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:59)
  4. at com.backendless.FootprintsManager$Inner.updateFootprintForObject(FootprintsManager.java:257)
  5. at com.backendless.FootprintsManager$Inner.updateFootprintForObject(FootprintsManager.java:238)
  6. at com.backendless.FootprintsManager$Inner.updateFootprintForObject(FootprintsManager.java:257)
  7. at com.backendless.Persistence$4.handleResponse(Persistence.java:196)
  8. at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
  9. at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
  10. at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
  11. at android.os.Handler.dispatchMessage(Handler.java:98)
  12. at android.os.Looper.loop(Looper.java:146)
  13. at android.app.ActivityThread.main(ActivityThread.java:5487)
  14. at java.lang.reflect.Method.invokeNative(Native Method)
  15. at java.lang.reflect.Method.invoke(Method.java:515)
  16. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
  17. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
  18. at dalvik.system.NativeStart.main(Native Method)

Here is CommentThread Class

  1. package com.example.mubtadanaqvi.stunexus;

    import android.util.Log;

    import com.backendless.BackendlessUser;

    import com.stfalcon.chatkit.commons.models.IDialog;

    import com.stfalcon.chatkit.commons.models.IMessage;

    import com.stfalcon.chatkit.commons.models.IUser;

    import java.util.ArrayList;

    import java.util.List;

    import weborb.service.ExcludeProperties;

    @ExcludeProperties( propertyNames = {"users","unreadCount","dialogName","dialogPhoto","lastMessage","id"})

    public class CommentThreads implements IDialog

    {

    private java.util.Date created;

    private String ownerId;

    private String objectId;

    private java.util.Date updated;

    private java.util.List<HelpComments> comments;

    private BackendlessUser helper;

    private int unRead=0;

    private String id;

    private String dialogPhoto;

    private String dialogName;

    private IMessage lastMessage;

    private List<IUser> usersList = new ArrayList<>();

    public java.util.Date getCreated()

    {

    return created;

    }

    public String getOwnerId()

    {

    return ownerId;

    }

    public String getObjectId()

    {

    return objectId;

    }

    public java.util.Date getUpdated()

    {

    return updated;

    }

    public java.util.List<HelpComments> getComments()

    {

    return comments;

    }

    public void setComments( java.util.List<HelpComments> comments )

    {

    this.comments = comments;

    }

    public void addComment(HelpComments comments){this.comments.add(0,comments);}

    public BackendlessUser getHelper()

    {

    return helper;

    }

    public void setHelper( BackendlessUser helper )

    {

    this.helper = helper;

    }

    @Override

    public String getId() {

    return getObjectId();

    }

    public void setId(String s){

    this.id=s;

    }

    @Override

    public String getDialogPhoto() {

    Log.d("test:",getHelper().getProperty("profileImage")+"");

    if (getHelper().getProperty("profileImage")==null)

    return null;

    else

    return getHelper().getProperty("profileImage").toString();

    }

    public void setDialogPhoto(String s){

    this.dialogPhoto=s;

    }

    @Override

    public String getDialogName() {

    return getHelper().getProperty("name").toString();

    }

    public void setDialogName(String s){

    this.dialogName=s;

    }

    @Override

    public List<IUser> getUsers() {

    return this.usersList;

    }

    public void setUsers(List<IUser> users){

    this.usersList=users;

    }

    @Override

    public IMessage getLastMessage() {

    if (getComments().size()>0)

    return getComments().get(0);

    // return getComments().get(getComments().size()-1);

    return null;

    }

    @Override

    public void setLastMessage(IMessage message) {

    this.lastMessage=message;

    }

    @Override

    public int getUnreadCount() {

    return unRead;

    }

    public void setUnreadCount(int i){

    this.unRead=i;

    }

    public void addUser(IUser user){

    this.usersList.add(user);

    }

    }

and Here is HelpComments-Class

  1. package com.example.mubtadanaqvi.stunexus;

    import android.util.Log;

    import com.backendless.BackendlessUser;

    import com.stfalcon.chatkit.commons.models.IMessage;

    import com.stfalcon.chatkit.commons.models.IUser;

    import java.util.Date;

    import weborb.service.ExcludeProperties;

    @ExcludeProperties( propertyNames = {"createdAt","id","text","user"})

    public class HelpComments implements IMessage

    {

    private String message;

    private String ownerId;

    private String objectId;

    private java.util.Date created;

    private java.util.Date updated;

    private BackendlessUser creator;

    private String id;

    private String text;

    private IUser user;

    private Date date;

    public String getMessage()

    {

    return message;

    }

    public void setMessage( String message )

    {

    this.message = message;

    }

    public String getOwnerId()

    {

    return ownerId;

    }

    public String getObjectId()

    {

    return objectId;

    }

    public java.util.Date getCreated()

    {

    return created;

    }

    public java.util.Date getUpdated()

    {

    return updated;

    }

    public BackendlessUser getCreator()

    {

    return creator;

    }

    public void setCreator( BackendlessUser creator )

    {

    this.creator = creator;

    }

    @Override

    public String getId() {

    return getObjectId();

    }

    public void setId(String s){

    this.id=s;

    }

    @Override

    public String getText() {

    return getMessage();

    }

    public void setText(String s){

    this.text=s;

    }

    public void setUser(IUser user){

    this.user=user;

    }

    @Override

    public IUser getUser() {

    DialogAuthor a= new DialogAuthor();

    a.setName(getCreator().getProperty("name").toString());

    // if (getCreator().getProperty("profileImage")==null)

    a.setAvtar(null);

    // else

    // a.setAvtar(getCreator().getProperty("profileImage").toString());

    Log.d("avtarNew:",getCreator().getProperty("profileImage").toString());

    a.setId(getCreator().getObjectId());

    return a;

    }

    public void setCreatedAt(Date date){

    this.date=date;

    }

    @Override

    public Date getCreatedAt() {

    return getCreated();

    }

    }

Leave a Comment

Comments (2)

photo
1

This error is known to happen when you have circular references in the data structures. For example, a Comment object references a User and a User references the Comment. From the code you posted earlier, this is what you have in your data structure. I recommend rethinking object relations in your app and simplify how they are established. It looks like you're over-engineering the solution.

Regards,

Mark

photo
1

Thanks, It works.