0

i am quite new into android coding and have been trying to practice on it. Recently i am trying to create a fuel efficiency calculator with a login and register function. When i tried clicking on the login button it crashes.

import androidx.appcompat.app.AppCompatActivity;

public class Login1 extends AppCompatActivity {

    Button bLogin, bRegister;
    EditText etUsername, etPassword;

    SharedPreferences preferences;

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

        etUsername = (EditText) findViewById(R.id.editText2);
        etPassword = (EditText) findViewById(R.id.editText);
        bLogin = (Button) findViewById(R.id.button);
        bRegister = (Button) findViewById(R.id.button2);

        preferences = getSharedPreferences("Userinfo", 0);

        bRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Login1.this, Register1.class);
                startActivity(intent);
            }
        });

        bLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String usernameValue = etUsername.getText().toString();
                String passwordValue =etPassword.getText().toString();

                String registeredUsername = preferences.getString("etUsername", "");
                String registeredPassword = preferences.getString("etPassword", "");

                if (usernameValue.equals(registeredUsername) && passwordValue.equals(registeredPassword)) {
                    Intent intent = new Intent(Login1.this, MainActivity.class);
                    startActivity(intent);
                }

                else {
                    Toast t = Toast.makeText(Login1.this, "Wrong email or password", Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        });
    }

Previously i had the same issue with register button but i happened to fix it by changing the intent name from i to intent. However this didn't work with my login button. Appreciate any assistance

Dinesh
  • 1,410
  • 2
  • 16
  • 29
  • Please [edit] your question to add the complete stack trace from the crash. The post linked above shows how to find it. – Mike M. May 12 '20 at 04:54
  • could you please post your Error log? – Flying Dutchman May 12 '20 at 05:08
  • 1
    Thanks for the clarification on the stack traces, i found the problem which is kinda amateur for me. Apparently i did not include my Main Activity in the manifest.xml which is causing the crash. – Jason C May 12 '20 at 07:02

0 Answers0