Search code examples
androidnullpointerexceptionhelpshift

Getting an error in Android studio when integrating the Helpshift API (null pointer exception)


I'm getting a null point exception in Android studio. I'm trying to integrate Helpshift into my current app. The null point is being called on the help button I think. The error I'm getting is:

java.lang.NullPointerException: Attempt to invoke interface method 
'void com.helpshift.CoreApi.updateApiConfig(java.util.Map)' on a null object reference

My code looks like

package com.example.leoconnelly.connexus;




public class MainActivity extends AppCompatActivity {

ImageButton FindCareButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


//THE PURPLE BUTTON!!!!!!!
    FindCareButton = (findViewById(R.id.find_care_button));

    FindCareButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openFindCare();
        }
    });

    /*
    GetStartedButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openSearchActivity();
        }
    });
     */

    ImageButton helpButton = (ImageButton) findViewById(R.id.imageButton13);
    helpButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ApiConfig.Builder configBuilder = new ApiConfig.Builder();
            configBuilder.setRequireEmail(true);
            configBuilder.setEnableTypingIndicator(true);
            com.helpshift.support.Support.showConversation(MainActivity.this, configBuilder.build() );


        }
    });


}

public void openFindCare () {
   Intent mainActivityToFindCare = new Intent (this, 
HealthCenterListActivity.class);
    startActivity(mainActivityToFindCare);
}

}

I'm not exactly sure what it's pointing too. I'm trying to open FAQs from Helpshift.


Solution

  • You are missing the InstallConfig for the API. Try adding it in the Calling Activity.

    import com.helpshift.Core;
    import com.helpshift.All;
    import com.helpshift.InstallConfig;
    import com.helpshift.exceptions.InstallException;
    
    Core.init(All.getInstance());
            InstallConfig installConfig = new InstallConfig.Builder()
                    .setEnableInAppNotification(true)
                    .build();
    
            try {
                Core.install(getApplication(),
                        API_KEY,
                        DOMAIN,
                        APP_ID, installConfig);
    
    
            } catch (InstallException e) {
                android.util.Log.e("Helpshift", "install call : ", e);
            }