user7085962 user7085962 - 3 months ago 24
Android Question

PutLong on a null Long in argument Bundle

Given a new instance method of a Fragment:

public static MyFragment newInstance(Long someLong) {
Bundle args = new Bundle();
MyFragment fragment = new WorkoutDetailsRoutineInfoFragment();
args.putLong(ARGS_LONG, someLong);
return fragment;

is null, this doesn't work.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'long java.lang.Long.longValue()' on a null object reference

How do I get it to store the Long even if it's null?


Check if its null and if its null add -1 if its not null add the Long object. Pretty easy