I have this code separate class which makes a Snackbar to be displayed within my application, But with my current implementation I am getting a 'java.lang.NullPointerException'. How do I implement it in my main class properly?
here is my snack bar class:
public class SnackBarUtils
{
private static SnackBarUtils mInstance = null;
private  Snackbar mSnackBar;
private SnackBarUtils()
{
}
public static SnackBarUtils getInstance()
{
    if (mInstance == null)
    {
        mInstance = new SnackBarUtils();
    }
    return mInstance;
}
public void hideSnackBar()
{
    if (mSnackBar != null)
    {
        mSnackBar.dismiss();
    }
}
public void showProblemSnackBar(final Activity activity, final String message)
{
    mSnackBar = Snackbar.make(activity.findViewById(android.R.id.content), message, 
    Snackbar.LENGTH_INDEFINITE);
    // Changing action button text color
    View sbView = mSnackBar.getView();
    TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text);
    mSnackBar.setAction("x", new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            //Call your action method here
            mSnackBar.dismiss();
        }
    });
    textView.setTextColor(Color.WHITE);
    sbView.setBackgroundColor(Color.RED);
    textView.setMaxLines(3);
    mSnackBar.show();
}
}
This is my current implementation within main activity, I have already Initialized the snackbar class like this:
SnackBarUtils snackBarUtils;
and then called it like this:
snackBarUtils.showProblemSnackBar(MainActivity.this, mPlainTextResponse);
what am I doing wrong? Or what is the correct way to do this?