This question has already been answered:
Good day.
Error java.lang.NullPointerException
Error on the line with the assignment.
If it has not yet been created, that is, default, why is NullPointerException ?
SharedPreferences settings; SharedPreferences.Editor editor; boolean ifWasSet; public void makeList() { ifWasSet = settings.getBoolean("comp", false); if (ifWasSet == true) { System.out.println("Ne dobavlyaem"); } else { persons.add(student1); persons.add(student2); persons.add(student3); persons.add(student4); settings = getApplicationContext().getSharedPreferences(STORAGE_NAME, Context.MODE_PRIVATE); editor = settings.edit(); editor.putBoolean("comp", true); editor.commit(); } }
if, and you assign a value to it only in theelseblock. That is how it should be? - Nikotin N