title: Why am I getting NullPointerException in `getResources().getStringArray()` while the Activity is already created?
body: <p>Why am I getting an NPE, when the <code>Activity</code> is already created/<code>context</code> is already initialized?</p>
  
  <p><strong>EXPLAINED:</strong></p>
  
  <p>I am inside a fragment's <code>onActivityCreated</code> method, which ensures the the <code>Activity</code> is already created, and thus the <code>context</code> is already initialized. I get the application resources like:</p>
  
  <pre><code>    @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          ...
          Resources appResources = getActivity().getResources();
          Log.i(TAG, "APPRESOURCES &gt;&gt;&gt; " + appResources.toString());//check
          ExpandableRecyclerViewAdapter expandableRecyclerView = new ExpandableRecyclerViewAdapter(getActivity(), populateList(appResources));
          ...
      }
  </code></pre>
  
  <p>The <code>Log.i</code> statement above prints</p>
  
  <pre><code>APPRESOURCES &gt;&gt;&gt; android.content.res.Resources@45fbef68
  </code></pre>
  
  <hr>
  
  <p>Inside the <code>populateList(appResources)</code> method called above, I create an object of <code>MyParentObject</code> and pass the <code>appResources</code> to its constructor:</p>
  
  <pre><code>private List&lt;ParentObject&gt; populateList(Resources appResources) {
          ...
          MyParentObject myParentObject = new MyParentObject(appResources);
          ...
  }
  </code></pre>
  
  <hr>
  
  <p>In the <code>MyParentObject</code> class,</p>
  
  <pre><code>public class MyParentObject implements ParentObject {   
          Resources appResources;     
          ...
          public MyParentObject(Resources appResources) {         
              this.appResources = appResources;   
          }
          ...    
          private String [] spinnerFields = appResources.getStringArray(R.array.spinnerFields_arrayResource);//******ERROR********
          ...  
      }
  </code></pre>
  
  <p><strong>The statement which assigns <code>spinnerFields</code> is where I get the NPE.</strong></p>
  
  <hr>
  
  <p><strong><em>NOTE: Initially, I was passing around a <code>context</code> object obtained from <code>getActivity()</code> in <code>onActivityCreated()</code> of the fragment. But during the process of debugging for this NPE, I changed to passing around the <code>appResources</code> object.</em></strong></p>