java - ToString on Object generate error -


i'm trying display object content. use orm. have delivery contains list of user. in delivery.tostring() make this:

    `     @override public string tostring() {     string usersreadables = "";      try {         closeableiterator<user> useriterator = this.getusers().closeableiterator();          try {             // each user.             while (useriterator.hasnext()) {                 usersreadables += usersreadables.length() > 0 ? ", " : "";                 user user = useriterator.next();                 usersreadables += user.getname();             }         } {             // close iterator, else connection database             // isn't destroyed.             try {                 useriterator.close();             } catch (sqlexception e) {                 log.e(databasehelper.class.getname(), e.getmessage(), e);             }         }     } catch (exception e) {         usersreadables = null;     }      return "delivery [deliveryid=" + deliveryid + ", round=" + round + ", typedelivery=" + typedelivery + ", priority=" + priority + ", deliveryover=" + deliveryover + ", receiveravailable=" + receiveravailable + ", signature=" + signature + ", dateover=" + dateover + ", latitude=" + latitude + ", longitude=" + longitude + ", users=" + usersreadables + ", sender=" + sender + ", receiver=" + receiver + "]"; }` 

but if try usersreadables += user.tostring(); program generate exception. don't understand why. had override user.tostring display correctly users but...

do have idea ? thank you.

it seems if reason you're getting error because userreadables set null string. in catch, have

catch(exception e) {    userreadables = null; } 

and since userreadables null, it's calling exception before else. make related program. change to

string userreadables = " "; 

that way @ least registered space, , not null.

hope helps!


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -