0

i m using a progress button library https://github.com/leandroBorgesFerreira/LoadingButtonAndroid for loginbutton ,when i am trying to create user by clicking this button in firebase i got belows errors

i found same error here java.lang.IllegalArgumentException : Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull but i am not able to get it

   java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bitmap
    at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.doneLoadingAnimation(Unknown Source:2)
    at com.choudhary.apnidukan.LoginActivity$1$1.onComplete(LoginActivity.java:82)

my loginActivity

public class LoginActivity extends AppCompatActivity {


EditText email, password, confirmpassword;

FirebaseAuth firebaseAuth;

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

    firebaseAuth = FirebaseAuth.getInstance();


    final CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id);

    email = findViewById(R.id.edit_text_email);
    password = findViewById(R.id.edit_text_password);
    confirmpassword = findViewById(R.id.edit_confirmPassword);


    btn.setOnClickListener(new View.OnClickListener() {



        @Override
        public void onClick(View view) {

            if (TextUtils.isEmpty(email.getText().toString())) {
                email.setError("Email is must");
                return;
            }

            if (TextUtils.isEmpty(password.getText().toString())) {
                password.setError("Password is must");
                return;
            }

            if (TextUtils.isEmpty(confirmpassword.getText().toString())) {
                confirmpassword.setError("Password not Matched");
                return;
            }

            if (!password.getText().toString().trim().equals(confirmpassword.getText().toString().trim())) {
                confirmpassword.setError("Password not matched");
                return;
            }

            String EMAIL = email.getText().toString();
            String PASSWORD = password.getText().toString();
            btn.startAnimation();

            final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_baseline_check_24);

            firebaseAuth.createUserWithEmailAndPassword(EMAIL, PASSWORD).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (task.isSuccessful()) {
                        btn.doneLoadingAnimation(R.color.colorPrimaryDark, bitmap);
                        Intent in = new Intent(LoginActivity.this, mainDrawerActivity.class);
                        startActivity(in);
                        finish();
                    } else {
                        btn.revertAnimation();
                        Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                          btn.stopAnimation();
                    }

                }
            });


        }
    });


}

}

vikram
  • 84
  • 9
  • Your call to decodeResource returned null. Which caused you to pass null into doneLoadingAnimation, which is an error. That function returns null if it there's an error when trying to load the bitmap. – Gabe Sechan Apr 19 '21 at 04:35

1 Answers1

0

Returned Bitmap is null at final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_baseline_check_24);. That's why you get error at btn.doneLoadingAnimation(R.color.colorPrimaryDark, bitmap);. To get correct bitmap from drawable you could use below method. Like:

    public static Bitmap drawableToBitmap (Drawable drawable) {
    Bitmap bitmap = null;

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if(bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

And call above method inside firebase callback method. Like:

    firebaseAuth.createUserWithEmailAndPassword(EMAIL, PASSWORD).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            if (task.isSuccessful()) {
                // Create Bitmap here------------------
                Bitmap bitmap = drawableToBitmap(getResources().getDrawable(R.drawable.ic_baseline_check_24));
                btn.doneLoadingAnimation(R.color.colorPrimaryDark, bitmap);
                Intent in = new Intent(LoginActivity.this, mainDrawerActivity.class);
                startActivity(in);
                finish();
            } else {
                btn.revertAnimation();
                Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                btn.stopAnimation();
            }

        }
    });
NRUSINGHA MOHARANA
  • 1,489
  • 8
  • 13