0
 public void doSignUp(OnAddUpdateListener<SignUpValidationError> listListener, SignUpRequest request) {
    mListener = listListener;
    LeafApiClient apiClient = LeafApplication.getInstance().getApiClient();
    LeafService service = apiClient.getService(LeafService.class);
    final Call<SignUpResponse> model = service.signup(request);
    ResponseWrapper<SignUpResponse> wrapper = new ResponseWrapper<>(model);

I'm getting a error on apiClient as : Cant invoke getApiClient() on a null object reference

 private LeafApiClient apiClient;
private static LeafApplication sInstance;

@Override
public void onCreate() {
    super.onCreate();
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    sInstance = this;


 public static LeafApplication getInstance(){
    return sInstance;
}

public synchronized LeafApiClient getApiClient(){
    if (apiClient == null){
        apiClient = LeafApiClient.getInstance(getApplicationContext());
    }
    return apiClient;
}

This is the code from where i invoke the method getApiClient

  • 2
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – David Rawson Jan 18 '17 at 10:09
  • Also, have you declared your Application in the manifest? – David Rawson Jan 18 '17 at 10:12
  • Sorry i'm new to android programming..... Can u please tell me what should i declare in the manifest???? –  Jan 18 '17 at 10:23
  • It's in the official guide https://developer.android.com/reference/android/app/Application.html You can provide your own implementation by creating a subclass and specifying the fully-qualified name of this subclass as the "android:name" attribute in your AndroidManifest.xml's tag. – David Rawson Jan 18 '17 at 10:27
  • I did that too... but I'm still getting the same error..... When i debug my code only getApiClient() method is not executing!!! –  Jan 18 '17 at 10:48
  • Can you put a break point on `onCreate()` inside your Application. Is it getting called? – David Rawson Jan 18 '17 at 19:44
  • onCreate is getting called and i also included the name attribute in manifest file..... but the debugging stops after LeafApiClient apiClient = LeafApplication.getInstance().getApiClient(); –  Jan 19 '17 at 05:13
  • 1
    Thank you for your help!!! I included the name attribute and rebuild the project... It works fine now!!!! –  Jan 19 '17 at 05:24
  • Well done! Glad the comnent helped – David Rawson Jan 19 '17 at 05:47
  • Ya it helped for sure!!!! Thank you!!! –  Jan 19 '17 at 09:29

0 Answers0