title: Android custom adapter getView() NullPointerException out of nowhere!
body: <p>I've got a custom Adapter to supply data for ListView. Everything worked fine, but 'suddenly'(I don't have another word for what's now happening) my app started crashing while loading my Activity with listview:</p>
  
  <pre><code>W/dalvikvm(  228): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  
  E/AndroidRuntime(  228): Uncaught handler: thread main exiting due to uncaught exception
  
  E/AndroidRuntime(  228): java.lang.NullPointerException
  
  E/AndroidRuntime(  228):    at AdvertisementListAdapter.getView(AdvertisementListAdapter.java:72)
  
  E/AndroidRuntime(  228):    at android.widget.AbsListView.obtainView(AbsListView.java:1274)
  
  E/AndroidRuntime(  228):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1147)
  
  E/AndroidRuntime(  228):    at android.widget.ListView.onMeasure(ListView.java:1060)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
  
  E/AndroidRuntime(  228):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
  
  E/AndroidRuntime(  228):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  
  E/AndroidRuntime(  228):    at android.view.View.measure(View.java:7964)
  
  E/AndroidRuntime(  228):    at android.view.ViewRoot.performTraversals(ViewRoot.java:763)
  
  E/AndroidRuntime(  228):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
  
  E/AndroidRuntime(  228):    at android.os.Handler.dispatchMessage(Handler.java:99)
  
  E/AndroidRuntime(  228):    at android.os.Looper.loop(Looper.java:123)
  
  E/AndroidRuntime(  228):    at android.app.ActivityThread.main(ActivityThread.java:4363)
  
  E/AndroidRuntime(  228):    at java.lang.reflect.Method.invokeNative(Native Method)
  
  E/AndroidRuntime(  228):    at java.lang.reflect.Method.invoke(Method.java:521)
  
  E/AndroidRuntime(  228):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  
  E/AndroidRuntime(  228):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  
  E/AndroidRuntime(  228):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>My getView method:</p>
  
  <pre><code>@Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          View view=convertView;
          ViewHolder holder;
  
          if(convertView==null){
              view=inflater.inflate(R.layout.list_item, null); 
              holder=new ViewHolder();
              holder.imgItemImage=(ImageView)view.findViewById(R.id.imgItemImage);
              holder.tvItemTitle=(TextView)view.findViewById(R.id.tvItemTitle);
              holder.tvItemDetails=(TextView)view.findViewById(R.id.tvItemDetails);
              view.setTag(holder);
          }else
              holder=(ViewHolder)view.getTag();
  
          holder.tvItemTitle.setText(data.get(position).getYear()+" "+data.get(position).getTitle());
  
          StringBuilder sb=new StringBuilder();
          sb.append(data.get(position).getPrice());
          sb.append("\n");
          sb.append(data.get(position).getCity());
          holder.tvItemDetails.setText(sb.toString());
  
  
          String imageUrl="http://myuri/"+data.get(position).getUrlList().get(0)+"/p-t.jpeg";
          holder.imgItemImage.setTag(imageUrl);
  
          imageLoader.displayImage(imageUrl, activity, holder.imgItemImage);
  
          return view;    
      }
  </code></pre>
  
  <p>When getView is first called, <code>convertView=null</code>, so <code>ViewHolder</code> object is created. But after calling <code>findViewById(...)</code> all members of ViewHolder class are still null. So, here are the origins <code>NullPointerException</code>. View inflating is successul as I can see during debug, <code>view</code> object contains <code>RelativeLayout</code> with it's children. 
  The worst thing is that I haven't changed this part of app before it started crashing!
  This is driving me nuts!</p>