0

I am trying to do something like this in android . I mean i have password text box and i am trying make visible a text view if password is correct but i am continuously showing a exception java.lang.nullpointerexception here is my code

public class MainActivity extends Activity {
    EditText Password;
    Button login;
    TextView txtDash;



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

        Password=(EditText)findViewById(R.id.pass);
        login=(Button)findViewById(R.id.login);

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View V) {
                try {
                if (Password.getText().toString().equals("dsml"))
                {

                    txtDash.setVisibility(View.VISIBLE);
                    login.setVisibility(View.INVISIBLE);
                    Password.setVisibility(View.INVISIBLE);

                }
                else
                {
                    Toast.makeText(getBaseContext(), "invalid password - try again",  Toast.LENGTH_SHORT).show();
                }
                }catch(Exception e){
                     //Log.e("log_tag", "Error"+e.toString());
                     Toast.makeText(getBaseContext(), e.toString(),  Toast.LENGTH_SHORT).show();
                }
            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Please any one help to getout of this

2 Answers 2

1

It looks like you are missing to get a reference to txtDash before you use it.

txtDash = (View)findViewById(R.id.id_for_your_view);
Sign up to request clarification or add additional context in comments.

Comments

1

Give refrence of txtDash from xml layout file as like as Password,login

Password=(EditText)findViewById(R.id.pass);
login=(Button)findViewById(R.id.login);

txtDash=(TextView)findViewById(R.id.txtdas); <<< You Forgot this line...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.