title: How to use ImageLoader of Volley Library?
body: <p>I am using volley library to load image from network and getting nullpointer exception. I am using it in Adapter class.Is there any problem in getting instance or what i am not getting. getView() throws nullpointerexception</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>VolleySingleton.java
  
  package com.w3nuts.babaa.helper;
  
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.support.v4.util.LruCache;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.toolbox.Volley;
  
  public class VolleySingleton {
  
   private static VolleySingleton instance;
   private RequestQueue requestQueue;
   private static ImageLoader imageLoader;
  
   private VolleySingleton(Context context) {
    requestQueue = Volley.newRequestQueue(context);
  
    imageLoader = new ImageLoader(requestQueue,
      new ImageLoader.ImageCache() {
       private final LruCache&lt;String, Bitmap&gt; cache = new LruCache&lt;String, Bitmap&gt;(
         20);
  
       @Override
       public Bitmap getBitmap(String url) {
        return cache.get(url);
       }
  
       @Override
       public void putBitmap(String url, Bitmap bitmap) {
        cache.put(url, bitmap);
       }
      });
   }
  
   public static VolleySingleton getInstance(Context context) {
    if (instance == null) {
     instance = new VolleySingleton(context);
    }
    return instance;
   }
  
   public RequestQueue getRequestQueue() {
    return requestQueue;
   }
  
   public static ImageLoader getImageLoader() {
    return imageLoader;
   }
  }
  
  
  ServiceListAdapter.class
  
  package com.w3nuts.babaa.adapter;
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.RatingBar;
  import android.widget.TextView;
  
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.toolbox.ImageLoader.ImageContainer;
  import com.android.volley.toolbox.ImageLoader.ImageListener;
  import com.android.volley.toolbox.NetworkImageView;
  import com.w3nuts.babaa.R;
  import com.w3nuts.babaa.getterSetter.ServiceDetailGetterSetter;
  import com.w3nuts.babaa.helper.VolleySingleton;
  
  public class ServiceListAdapter extends BaseAdapter {
  
   private Activity activity;
   private LayoutInflater inflater;
   private ArrayList&lt;ServiceDetailGetterSetter&gt; serviceDetailList;
  
   // Typeface tfRegular, tfLight;
  
   public ServiceListAdapter(Activity activity,
     ArrayList&lt;ServiceDetailGetterSetter&gt; serviceDetailList) {
    this.activity = activity;
    this.serviceDetailList = serviceDetailList;
   }
  
   @Override
   public int getCount() {
    return serviceDetailList.size();
   }
  
   @Override
   public Object getItem(int position) {
    return serviceDetailList.get(position);
   }
  
   @Override
   public long getItemId(int position) {
    return position;
   }
  
   private class ViewHolder {
    RatingBar ratingBar;
    TextView name;
    TextView location;
    TextView rating;
    NetworkImageView image;
   }
  
   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
  
    View view = convertView;
    if (convertView == null) {
     inflater = activity.getLayoutInflater();
     convertView = inflater.inflate(R.layout.service_list_item, null);
  
     holder = new ViewHolder();
     holder.name = (TextView) convertView.findViewById(R.id.name);
     holder.location = (TextView) convertView
       .findViewById(R.id.location);
     holder.rating = (TextView) convertView
       .findViewById(R.id.rating_text);
     holder.image = (NetworkImageView) convertView
       .findViewById(R.id.task_image);
     holder.ratingBar = (RatingBar) convertView
       .findViewById(R.id.rating_bar);
     convertView.setTag(holder);
    } else {
     holder = (ViewHolder) convertView.getTag();
    }
  
    holder.name.setText(serviceDetailList.get(position).getTitle());
    holder.location.setText(serviceDetailList.get(position).getLocation());
    holder.rating.setText(serviceDetailList.get(position).getRating() + "");
    holder.ratingBar.setRating((float) serviceDetailList.get(position)
      .getRating());
    // ////VOLLEY IMAGE LOADER
    String url = serviceDetailList.get(position).getImage();
    ImageLoader imageLoader = VolleySingleton.getImageLoader();
  
    imageLoader.get(url, new ImageListener() {
  
     public void onErrorResponse(VolleyError error) {
      holder.image.setImageResource(R.drawable.ic_launcher);
     }
  
     public void onResponse(ImageContainer response, boolean arg1) {
      if (response.getBitmap() != null) {
       holder.image.setImageBitmap(response.getBitmap());
      }
     }
    });
  
    Log.i("title", serviceDetailList.get(position).getTitle());
    Log.i("location", serviceDetailList.get(position).getLocation());
    Log.i("image", serviceDetailList.get(position).getImage());
    // SET TEXT AND IMAGE HERE
  
    return convertView;
   }
  }
  
  
  
  Service_list_item.xml
  
   &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" &gt;
  
          &lt;com.android.volley.toolbox.NetworkImageView
              android:id="@+id/task_image"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:adjustViewBounds="true"
              android:scaleType="centerInside"
              android:src="@drawable/task_demo_image" /&gt;
      &lt;/LinearLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>03-03 18:40:14.909: E/AndroidRuntime(6317): FATAL EXCEPTION: main
  03-03 18:40:14.909: E/AndroidRuntime(6317): java.lang.NullPointerException
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at com.w3nuts.babaa.adapter.ServiceListAdapter.getView(ServiceListAdapter.java:93)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.AbsListView.obtainView(AbsListView.java:2177)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.ListView.makeAndAddView(ListView.java:1840)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.ListView.fillDown(ListView.java:675)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.ListView.fillFromTop(ListView.java:736)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.ListView.layoutChildren(ListView.java:1655)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.AbsListView.onLayout(AbsListView.java:2012)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.View.layout(View.java:14289)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.Choreographer.doFrame(Choreographer.java:532)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.os.Handler.handleCallback(Handler.java:730)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.os.Handler.dispatchMessage(Handler.java:92)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.os.Looper.loop(Looper.java:137)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at java.lang.reflect.Method.invoke(Method.java:525)
  03-03 18:40:14.909: E/AndroidRuntime(6317):     at com.andr</p>