avoid NullPointerException at the first cycle
- by user1508419
I have this piece of code:
EventSnapshot snapshotEvent = new EventSnapshot();
EventSnapshot currentEvent = new EventSnapshot();
do
{
...
currentEvent.setContent(in_stats);
...
if(!snapshotEvent.equals(currentEvent))
snapshotEvent.setContent(in_stats);
}
while(true);
At the first cycle I get a NullPointerException because obviously the object snapshotEvent is empty. At the second cycle this doesn't happen.how can avoid this problem?