title: Hiding ListView Row if Array[Position] is Null
body: <p>Here is the code in the <code>getView</code> method of my <code>Custom ListView Adapter</code>. It gives me a <code>NullPointerException</code>. Can someone explain to my why this is happening? I am trying to inflate a custom listView row called "null_row" if text2 at any position in the array is null.</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      final Holder holder;
      View v = convertView;
      if (v == null) {
          holder = new Holder();
  
          if (text2[position] != null) {
  
              v = inflater.inflate(R.layout.detailrow, null);
  
          } else {
  
              v = inflater.inflate(R.layout.null_row, null);
  
          }
  
          holder.tv1 = (TextView) v.findViewById(R.id.leftside);
          holder.tv2 = (TextView) v.findViewById(R.id.rightside);
  
          v.setTag(holder);
  
      } else {
  
          holder = (Holder) v.getTag();
      }
  
      holder.tv1.setText(text1[position]);
      holder.tv2.setText(text2[position]);
  
      return v;
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <pre><code>01-04 09:26:54.912 18405-18405/app.example.app.example.app.flavor E/AndroidRuntime: FATAL EXCEPTION: main
  Process: app.example.app.example.myapp.flavor, PID: 18405
  java.lang.NullPointerException
  at app.example.myapp.Adapter.getView(Adapter.java:74)
  at android.widget.AbsListView.obtainView(AbsListView.java:2255)
  at android.widget.ListView.makeAndAddView(ListView.java:1790)
  at android.widget.ListView.fillDown(ListView.java:691)
  at android.widget.ListView.fillFromTop(ListView.java:752)
  at android.widget.ListView.layoutChildren(ListView.java:1630)
  at android.widget.AbsListView.onLayout(AbsListView.java:2087)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037)
  at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747)
  at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
  at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1156)
  at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:760)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
  at android.view.View.layout(View.java:14817)
  at android.view.ViewGroup.layout(ViewGroup.java:4631)
  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
  at android.view.Choreographer.doCallbacks(Choreographer.java:574)
  at android.view.Choreographer.doFrame(Choreographer.java:544)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
  at android.os.Handler.handleCallback(Handler.java:733)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5001)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>