title: Problems setting stored background color for ListView index
body: <p>I made a note-taking app using a ListView layout. The user can click on a note and set its color. That color is applied to the EditText background and to its corresponding ListView item. However, the colors reset when I exit the app. How can I set the saved color configurations for each ListView index whenever the app is opened?   </p>
  
  <p>I tried using SharedPreferences to save and load the colors but I keep getting errors and the app wont even open. I also tried tagging the colors suggested by another StackOverflow post but I get the same errors. </p>
  
  <p>MainActivity.java</p>
  
  <pre><code> static int pos = 0;
   static String c = "";
   static ListView listBackground;
  
   protected void onCreate(Bundle savedInstanceState) {
  
   listBackground = findViewById(R.id.listView);
  
   // LOAD DATA FROM EditNote.java
   sharedPreferences = getApplicationContext().getSharedPreferences("com.example.syeds.notesapp", MODE_PRIVATE);
  
   //ATTEMPT TO SET COLOR OF CHILD  
   for(int count = 0; count &lt; notes.size(); count++){
              String color = sharedPreferences.getString("color", null);
              listBackground.getChildAt(count).setBackgroundColor(Color.parseColor(color));
  
          }
  
  
   final ListView listView = findViewById(R.id.listView);
  
   listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      //THIS IS WHERE USER IS TAKEN TO EditNote.java   ` 
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
       Intent intent = new Intent(getApplicationContext(),EditNote.class);       
              intent.putExtra("notePosition",position);     
              startActivity(intent);
          }
      });
  </code></pre>
  
  <p>EditNote.java</p>
  
  <pre><code>String color;
  int position;
  
   @Override
    protected void onCreate(Bundle savedInstanceState) {
  
      final EditText editText = findViewById(R.id.editText);
      Intent intent = getIntent();
  
      //Get the position of array index
      position = intent.getIntExtra("notePosition", -1);
  
  } 
      //EXAMPLE METHOD FOR ONE COLOR(OTHERS NOT INCLUDED IN SAMPLE)
      public void changeGreen(View view) {   
  
      //Set color
      color = "#D4EFDF";
      MainActivity.listBackground.getChildAt(position).setBackgroundColor(Color.parseColor(color));
  
      //ATTEMPT TO SAVE COLOR
      sharedPreferences.edit().putString("color",color).apply();
  
  
      //Sets background of EditText
      background = findViewById(R.id.editText);
      background.setBackgroundColor(Color.parseColor("#D4EFDF"));
  }
  </code></pre>
  
  <p>For all the things I tried that are mentioned above, I get this error:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.String.charAt(int)' on a null object reference
      at android.graphics.Color.parseColor(Color.java:1384)
      at com.example.syeds.notesapp.MainActivity.onCreate(MainActivity.java:61)
  </code></pre>