title: How to fetch data using Retrofit in Listview
body: <p>I am getting a nullPointException in my adapter class.</p>
  
  <p>I want to get contact from server containing name and email.
  my Contact class is</p>
  
  <pre><code>public class Contact {
  
  @SerializedName("name")
  private String Name;
  
  @SerializedName("email")
  private String Email;
  
  
  public String getName() {
      return Name;
  }
  
  public String getEmail() {
      return Email;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>ApiClient CLass</p>
  
  <pre><code>public class ApiClient {
  
  private static final String BASE_URL = "http://192.168.43.88/ContactApp/";
  public static Retrofit retrofit = null;
  
  public static Retrofit getApiClient (){
  
      if (retrofit == null){
          retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
      }
  
      return retrofit;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>this is an adapter class where I am getting <strong>null pointer exception in infalter</strong> </p>
  
  <p>public class RetrofitItemAdapter extends BaseAdapter{</p>
  
  <pre><code>Context mContext;
  private List&lt;Contact&gt; mContact;
  RecyclerView.ViewHolder vh = null;
  
  //Constructor
  
  
  public RetrofitItemAdapter(List&lt;Contact&gt; mContact) {
  
      this.mContact = mContact;
  }
  
  
  public  class ViewHolder {
  
      public TextView tvName;
      public TextView tvEmail;
  
  
  }
  
  
  @Override
  public int getCount() {
      return mContact.size();
  }
  
  @Override
  public Object getItem(int position) {
      return mContact.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup viewGroup) {
  
      View vi = convertView;
      ViewHolder holder;
  
      if (convertView == null) {
  
          LayoutInflater inflater;
          inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
  
          vi = inflater.inflate(R.layout.listview_retrofit_items, null);
  
          holder = new ViewHolder();
          holder.tvName  = (TextView) vi.findViewById(R.id.tv_ret_name);
          holder.tvEmail  = (TextView) vi.findViewById(R.id.tv_ret_email);
  
  
          vi.setTag(holder);
  
      } else
          holder = (ViewHolder) vi.getTag();
  
      // now set your text view here like
  
     // holder.tvName.setText("Bla Bla Bla");
  
      holder.tvName.setText(mContact.get(position).getName());
      holder.tvEmail.setText(mContact.get(position).getEmail());
  
  
      // return your view
      return vi;
  </code></pre>
  
  <p>and finally my main class is</p>
  
  <pre><code>public class RetrofitDemo extends AppCompatActivity {
  
  private ListView listView;
  private List&lt;Contact&gt; contacts;
  private RetrofitItemAdapter adapter;
  private ApiInterface apiInterface;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_retrofit_demo);
  
      listView = (ListView)findViewById(R.id.lv_retrofitData);
  
      apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
      Call&lt;List&lt;Contact&gt;&gt; call = apiInterface.getContacts();
  
      call.enqueue(new Callback&lt;List&lt;Contact&gt;&gt;() {
          @Override
          public void onResponse(Call&lt;List&lt;Contact&gt;&gt; call, Response&lt;List&lt;Contact&gt;&gt; response) {
  
              contacts = response.body();
  
              adapter = new RetrofitItemAdapter(contacts);
              listView.setAdapter(adapter);
  
          }
  
          @Override
          public void onFailure(Call&lt;List&lt;Contact&gt;&gt; call, Throwable t) {
  
          }
      });
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Logcat error</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.example.admin.myapplication, PID: 2528
                                               java.lang.NullPointerException
                                                   at com.example.admin.myapplication.RetrofitItemAdapter.getView(RetrofitItemAdapter.java:66)
                                                   at android.widget.AbsListView.obtainView(AbsListView.java)
                                                   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)
                                                   at android.view.View.layout(View.java:14834)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:4631)
                                                   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
                                                   at android.view.View.layout(View.java:14834)
                                                   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:14834)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:4631)
                                                   at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:437)
                                                   at android.view.View.layout(View.java:14834)
                                                   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:14834)
                                                   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:14834)
                                                   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:14834)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:4631)
                                                   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1988)
                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1745)
                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1001)
                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5623)
                                                   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:5241)
                                                   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:818)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
                                                   at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>where is my mistake please help me 
  Thanks</strong></p>