title: how to fix 401 Unauthorized error with using retrofit in android?
body: <p>I have used retrofit2 library in android. I am getting 401 Unauthorized error. if anyone have solved this issue so please tell me here. I learn retrofit2 use in android.
  this is APIClient class.
              APIClient class :  </p>
  
  <pre><code>           public class APIClient {
                  private static Retrofit retrofit = null;
                  private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
                          .connectTimeout(7, TimeUnit.MINUTES)
                          .readTimeout(7, TimeUnit.MINUTES)
                          .writeTimeout(7, TimeUnit.MINUTES)
                          .build();
                  public static Retrofit getClient() {
                      HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
                      interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                      OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
  
                      retrofit = new Retrofit.Builder().baseUrl("http://www.example.com/").addConverterFactory(GsonConverterFactory.create())
                              .client(okHttpClient).build();
  
                      return retrofit;
                  }
              }
  </code></pre>
  
  <p>this is my interface. </p>
  
  <pre><code>                    public interface APIInterface {
                          @GET("/teacher/api/getStudentTakeAttendanceList")
                          Call&lt;List&lt;Apiresponse&gt;&gt; getstudentAttendanceListView(@Query("teacherId") int userId);
  
                      //    Callback&lt;List&lt;Apiresponse&gt;&gt; studentAttendanceListView(@Query("teacherId") int userId);
                      }         
  </code></pre>
  
  <p>this is my final call.</p>
  
  <pre><code>final Call&lt;List&lt;Apiresponse&gt;&gt; getstudentAttendanceListView = apiInterface.getstudentAttendanceListView(userId);
              getstudentAttendanceListView.enqueue(new Callback&lt;List&lt;Apiresponse&gt;&gt;() {
                      @Override
                      public void onResponse(Call&lt;List&lt;Apiresponse&gt;&gt; call, Response&lt;List&lt;Apiresponse&gt;&gt; response) {
                          Log.d("responsecode:::", "" + response.code());
  
                          if (progressDialog.isShowing()) {
                              progressDialog.dismiss();
                          }
  
                          Log.e("response::", "" + response.errorBody());
  
      //                    Log.e("response::", "" + response.body());
  
                      }
  
                      @Override
                      public void onFailure(Call&lt;List&lt;Apiresponse&gt;&gt; call, Throwable t) {
                          call.cancel();
                          if (progressDialog.isShowing()) {
                              progressDialog.dismiss();
                          }
  
                      }
                  });
  in app.gradle file.
          compile 'com.squareup.retrofit2:retrofit:2.0.2'
          compile 'com.squareup.retrofit2:converter-gson:2.0.2'
      output.
      responsecode:::: 401
      response::: okhttp3.ResponseBody$1@537beb4c
  </code></pre>