title: Robolectric: testing a ListView with ViewHolder pattern cause NullPointerException
body: <p>I have a <code>ListActivity</code> that it's adapter implements the ViewHolder pattern.</p>
  
  <p>the adapter and viewholder:</p>
  
  <pre><code>private class PlaceAdapter extends ArrayAdapter&lt;PlaceModel&gt; {
      final int viewResourceId;
  
      public PlaceAdapter(Context context, int textViewResourceId, List&lt;PlaceModel&gt; objects) {
          super(context, textViewResourceId, objects);
          viewResourceId = textViewResourceId;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
  
          if (convertView == null) {
              LayoutInflater inflater = getLayoutInflater();
              convertView = inflater.inflate(viewResourceId, null);
  
              holder = new ViewHolder(convertView);
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          PlaceModel place = getItem(position);
  
          holder.name.setText(place.getName());
          holder.address.setText(place.getVicinity());
  
          return convertView;
      }
  }
  
  private class ViewHolder {
      public final ImageView image;
      public final TextView name;
      public final TextView address;
  
      public ViewHolder(View row) {
          image = (ImageView) row.findViewById(R.id.placeRow_imageView);
          name = (TextView) row.findViewById(R.id.placeRow_placeName);
          address = (TextView) row.findViewById(R.id.placeRow_placeAddress);
      }
  }
  </code></pre>
  
  <p>when I'm running Robolectric tests with on this class I'm getting a <code>NullPointerException</code> on the <code>holder.name.setText</code> and <code>holder.address.setText</code> lines.</p>
  
  <p>my guess is that Robolectric doesn't handle <code>row.findViewById</code> correctly.</p>
  
  <p>how can I fix that ?</p>
  
  <p>this is the exception:</p>
  
  <pre><code>java.lang.NullPointerException
  at com.dgti.ds.activities.ChooseLocationActivity$PlaceAdapter.getView(ChooseLocationActivity.java:181)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView.addViews(ShadowAdapterView.java:314)
  at com.xtremelabs.robolectric.shadows.ShadowListView.addViews(ShadowListView.java:167)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView.update(ShadowAdapterView.java:302)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView.access$100(ShadowAdapterView.java:19)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView$1.run(ShadowAdapterView.java:85)
  at com.xtremelabs.robolectric.util.Scheduler.postDelayed(Scheduler.java:36)
  at com.xtremelabs.robolectric.shadows.ShadowLooper.post(ShadowLooper.java:154)
  at com.xtremelabs.robolectric.shadows.ShadowHandler.postDelayed(ShadowHandler.java:52)
  at com.xtremelabs.robolectric.shadows.ShadowHandler.post(ShadowHandler.java:47)
  at android.os.Handler.post(Handler.java)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView.invalidateAndScheduleUpdate(ShadowAdapterView.java:81)
  at com.xtremelabs.robolectric.shadows.ShadowAdapterView.setAdapter(ShadowAdapterView.java:45)
  at com.xtremelabs.robolectric.shadows.ShadowListView.setAdapter(ShadowListView.java:83)
  at android.widget.ListView.setAdapter(ListView.java)
  at com.dgti.ds.activities.ChooseLocationActivity.onSuccess(ChooseLocationActivity.java:119)
  at com.dgti.ds.activities.ChooseLocationActivityTests$1.answer(ChooseLocationActivityTests.java:105)
  at com.dgti.ds.activities.ChooseLocationActivityTests$1.answer(ChooseLocationActivityTests.java:96)
  at org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationMatcher.java:34)
  at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:91)
  at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
  at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
  at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:51)
  at com.dgti.ds.service.DsServiceHelperImp$$EnhancerByMockitoWithCGLIB$$34fcae5f.placeSearch(&lt;generated&gt;)
  at com.dgti.ds.service.DsServiceHelper.placeSearch(DsServiceHelper.java:278)
  at com.dgti.ds.activities.ChooseLocationActivity.placeSearch(ChooseLocationActivity.java:153)
  at com.dgti.ds.activities.ChooseLocationActivity.doSearch(ChooseLocationActivity.java:148)
  at com.dgti.ds.activities.ChooseLocationActivity.onCreate(ChooseLocationActivity.java:52)
  at com.dgti.ds.activities.ChooseLocationActivityTests.shouldAddPlacesToAdapterOnAPISuccessIfGoogleAPIKeyAlreadySet(ChooseLocationActivityTests.java:112)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
  at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
  at com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:288)
  at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  </code></pre>