title: SetText NullPointerException in Custom Adapter
body: <p>The custom adapter class forms a view but gives a null pointer exception while setting the text of list items.</p>
  
  <p><strong>NotificatitionAdabter.java</strong></p>
  
  <pre><code> public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder mViewHolder;
      if (convertView == null) {
          convertView = inflater.inflate(R.layout.row, parent, false);
          mViewHolder = new ViewHolder(convertView);
          convertView.setTag(mViewHolder);
      } else {
          mViewHolder = (ViewHolder) convertView.getTag();
  
      }
  
      MessageModel currentListData = getItem(position);
  
     Log.i(tag,mViewHolder.source.getText().toString());
  
      try {
          mViewHolder.name.setText(currentListData.getName());
          mViewHolder.source.setText(currentListData.getSource());
          Log.i(tag, currentListData.getName());
          mViewHolder.destination.setText(currentListData.getDestination());
          mViewHolder.message.setText(currentListData.getMessage());
          mViewHolder.time.setText(currentListData.getTime());
      }
      catch(Exception e){}//Log.i(tag,"4");
      if(convertView==null)
          Log.i(tag,"null");
      else
          Log.i(tag,"not null");
      return convertView;
  }
  </code></pre>
  
  <p>The gettext is also working for the above view but setText giving NPE.Double checked all xml files for any typo</p>
  
  <pre><code>    public class ViewHolder {
      TextView name;
      TextView source;
      TextView destination;
      TextView message;
      TextView time;
      public ViewHolder(View item) {
          name=(TextView) item.findViewById(R.id.lblname);
          destination=(TextView) item.findViewById(R.id.lblDestination);
          message=(TextView) item.findViewById(R.id.lblSCustMsg);
          time=(TextView) item.findViewById(R.id.lblSTime);
          source=(TextView) item.findViewById(R.id.lblSSource);
      }
  }
  </code></pre>
  
  <p><strong>DataSourceModel</strong></p>
  
  <pre><code>public class MessageModel {
  String source,destination,custmsg,time,name;
  public MessageModel(String source,
                      String destination,String custmsg,
                      String time,String name)
  {
      this.source=source;
      this.destination=destination;
      this.custmsg=custmsg;
      this.time=time;
      this.name=name;
  }
  public String getName()
  {
      return name;
  }
  public String getSource()
  {
      return source;
  }
  public String getTime()
  {
      return time;
  }
  public String getMessage()
  {
      return custmsg;
  }
  public String getDestination()
  {
      return destination}} 
  </code></pre>
  
  <p><strong>Debug</strong></p>
  
  <pre><code>4-17 23:47:19.378 23874-23874/com.example.abc.myapplication E/AndroidRuntime:FATAL EXCEPTION: main
                                                                           java.lang.NullPointerException
                                                                                 at com.example.abc.myapplication.NotificationAdapter.getView(NotificationAdapter.java:76)
                                                                                 at android.widget.AbsListView.obtainView(AbsListView.java:2340)
                                                                                 at android.widget.ListView.measureHeightOfChildren(ListView.java:1250)
                                                                                 at android.widget.ListView.onMeasure(ListView.java:1162)
                                                                                 at android.view.View.measure(View.java:15264)
                                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
                                                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
                                                                                 at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
                                                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
                                                                                 at android.view.View.measure(View.java:15264)
                                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
                                                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                                 at android.view.View.measure(View.java:15264)
                                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
                                                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
                                                                                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
                                                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
                                                                                 at android.view.View.measure(View.java:15264)
                                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
                                                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                                 at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2161)
                                                                                 at android.view.View.measure(View.java:15264)
                                                                                 at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2131)
                                                                                 at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1242)
                                                                                 at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1435)
                                                                                 at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1127)
                                                                                 at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4609)
                                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:747)
                                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:567)
                                                                                 at android.view.Choreographer.doFrame(Choreographer.java:536)
                                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:733)
                                                                                 at android.os.Handler.handleCallback(Handler.java:615)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                 at android.os.Looper.loop(Looper.java:153)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:4987)
                                                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
                                                                                 at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>row.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"&gt;
  
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/lblSName"
      android:text="item" /&gt;
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
  
      android:id="@+id/lblSTime"
      android:text="item" /&gt;
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
  
      android:id="@+id/lblSSource"
      android:text="item" /&gt;
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
  
      android:id="@+id/lblSDestination"
      android:text="item" /&gt;
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
  
      android:id="@+id/lblSCustMsg"
      android:text="item" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>getitem method of adapter class</strong></p>
  
  <pre><code> public MessageModel getItem(int position) {
  
      return myList.get(position);
  }
  </code></pre>