i cannot go to another page and please solve the problem for me.

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Sep 15, 2017 4:24:30 AM via Website

Button signin;
EditText editTextUsername,editTextPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    signin=(Button)findViewById(R.id.login);
    editTextUsername=(EditText)findViewById(R.id.username);
    editTextPassword=(EditText)findViewById(R.id.password);

    signin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String username=String.valueOf(editTextUsername);
            String password=String.valueOf(editTextPassword);

            if(username.equals("admin") && password.equals("admin"))
            {
                Intent intent=new Intent(MainActivity.this,SecondPage.class);
                startActivity(intent);
            }
            else
            {
                Intent intent=new Intent(MainActivity.this,MainActivity.class);
            }

        }
    });
}

i can't go to next page.

  • Forum posts: 7

Sep 15, 2017 3:44:02 PM via Website

Hay, Cjmah, put JOptionPane.showMessageDialog(ex, Exception); into try and catch and share, what exception you get from it?

  • Forum posts: 2

Sep 19, 2017 9:17:30 AM via Website

in these lines what is the value you are getting ,I don't think you are getting value from editext, Use getText() for getting text and convert to string using toString()

String username=String.valueOf(editTextUsername);
String password=String.valueOf(editTextPassword);

— modified on Sep 19, 2017 9:37:41 AM

  • Forum posts: 8

Sep 20, 2017 8:30:51 AM via Website

Hi there,

Instead of using
String username=String.valueOf(editTextUsername);

try using
String username = editTextUsername.getText().toString();

then do the same with password field too.