Why am I getting null in onCreate? How can I intialise : it might be a trivial question, if so I'm sorry-I'm new to Java. Basically, I'm trying to set list equal to a sharedPreference that is saved. However the app keeps on crashing because the list is null to begin with. As you can see I have tried to initialise it. I need list to be public because I use it in another method. So the relevant code looks something like this




public class SecondActivity extends AppCompatActivity {

	public int[] list = { 1, 1, 1, 1, 1, 1 };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_second);
		if (list == null) {
			for (int i : list) {
				i = 1;
			}
		}
		list = getFromPrefs("updateList");
		Log.i("is Correct is ", Arrays.toString(list));
	}}