Error calling android studio java method

Asked

Viewed 91 times

0

I’m having the error of: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

when trying to call a method, according to the code below:

    public void return_profile_infos(String result_id) {
        idasync=null;
        idtxt.setText(result_id);
        idasync=result_id;
        p.hide();
        verifylogin();
    }

    public void verifylogin() {
        if ((idasync!=null))   {
        tst1 = getString(R.string.act_profile_wlcm_msg);
           Toast.makeText(Profile.this,tst1+", id= "+ idasync,Toast.LENGTH_SHORT).show();
        }
        else
        {
        startActivity(new Intent(Profile.this,MainActivity.class));
        finish();
        }
    }

The mistake happens when I try to call the method verifylogin() from the return_profile_infos . I’ve been trying for hours and I can’t solve, my app gives the message that the app has stopped.

From j[a thank you who proposes to help.

Thank you.

  • Check the "tst1" object in the verifylogin() method, see if there is any value assigned to it.

  • also check that Edit objects are instantiated correctly with the layout

  • Thanks for the help! I did one more search on this and found that the error occurs due to the destruction of the fragment that Toast uses to execute, in my context, I realized that it would be more feasible to remove it from my code instead of fixing this problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.