java - Return and break in foreach-loop ArrayList -
i try execute function.
private arraylist<note> notes; //adding notes in arraylist public note getnotebyday(calendar calendar) { (note note : notes) { if (note.getreminder().gettime() / constants.day_in_millis == calendar.gettimeinmillis() / constants.day_in_millis) { log.d("note_id", note.getname()); return note; } } return null; }
but when call function different calendar
- i first note.
- i 2 calls of
log.d()
. - when use
break;
insteadreturn note;
1 call oflog.d()
where problem?
1) first note.
that's because first note fulfill requirements in if statement.
2) 2 calls of log.d().
it means issue not in code in place calls method. use debugger or stacktrace determine , when calls method. multithread or multiclick - whatever environment or platform using.
3) when use break; instead return note; 1 call of log.d() problem?
that confirms case 2. on break returns null , calling place has null pointer exception , not call again.
bottom line - issue not in provided code in place method called. eclipse has nice feature - shows method used - use feature.
Comments
Post a Comment