user7085962 user7085962 - 1 year ago 92
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download