Sorry if I’m missing something obvious here, but I’m confused about what’s going on. I declare Workout mWorkout; as an instance variable at the top of my class. Up until this point, it hasn’t been initialized.
This code works: createWorkout returns a Workout object, which is stored in the local variable test, and then the instance variable mWorkout is set from that.
public void startWorkout() {
Workout test = workoutFactory.createWorkout();
mWorkout = test;
}
Whereas this code doesn’t:
public void startWorkout() {
mWorkout = workoutFactory.createWorkout();
}
mWorkout remains null even though createWorkout is still returning a Workout object.
Above code is slightly simplified for clarity.
Try qualifying
mWorkoutwiththis.My assumption is that you have defined a local
mWorkoutthat’s shadowing your instance variable with the same name.