-2

I have created two activities: one for log in and a second one for navigation drawer. But when I log in it accepts e-mail and password but does not go on next activity, it shows app has stopped.

My log in code:

public class  LoginActivity extends AppCompatActivity implements    
View.OnClickListener {
private final AppCompatActivity activity = LoginActivity.this;

private NestedScrollView nestedScrollView;

private TextInputLayout textInputLayoutEmail;
private TextInputLayout textInputLayoutPassword;

private TextInputEditText textInputEditTextEmail;
private TextInputEditText textInputEditTextPassword;

private AppCompatButton appCompatButtonLogin;

private AppCompatTextView textViewLinkRegister;

private InputValidation inputValidation;
private DatabaseHelper databaseHelper;

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

    initViews();
    initListeners();
    initObjects();
}

/**
 * This method is to initialize views
 */
private void initViews() {

    nestedScrollView = (NestedScrollView) findViewById(R.id.nestedScrollView);

    textInputLayoutEmail = (TextInputLayout) findViewById(R.id.textInputLayoutEmail);
    textInputLayoutPassword = (TextInputLayout) findViewById(R.id.textInputLayoutPassword);

    textInputEditTextEmail = (TextInputEditText) findViewById(R.id.textInputEditTextEmail);
    textInputEditTextPassword = (TextInputEditText) findViewById(R.id.textInputEditTextPassword);

    appCompatButtonLogin = (AppCompatButton) findViewById(R.id.appCompatButtonLogin);

    textViewLinkRegister = (AppCompatTextView) findViewById(R.id.textViewLinkRegister);

}

/**
 * This method is to initialize listeners
 */
private void initListeners() {
    appCompatButtonLogin.setOnClickListener(this);
    textViewLinkRegister.setOnClickListener(this);
}

/**
 * This method is to initialize objects to be used
 */
private void initObjects() {
    databaseHelper = new DatabaseHelper(activity);
    inputValidation = new InputValidation(activity);

}

/**
 * This implemented method is to listen the click on view
 *
 * @param v
 */
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.appCompatButtonLogin:
            verifyFromSQLite();
            break;
        case R.id.textViewLinkRegister:
            // Navigate to RegisterActivity
            Intent intentRegister = new Intent(getApplicationContext(), RegisterActivity.class);
            startActivity(intentRegister);
            break;
    }
}

/**
 * This method is to validate the input text fields and verify login credentials from SQLite
 */
private void verifyFromSQLite() {
    if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
        return;
    }
    if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
        return;
    }
    if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword, textInputLayoutPassword, getString(R.string.error_message_email))) {
        return;
    }

    if (databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim()
            , textInputEditTextPassword.getText().toString().trim())) {

        Intent accountsIntent = newIntent(activity,NavigationDrawer.class);

        startActivity(accountsIntent);

    } else {
        // Snack Bar to show success message that record is wrong
        Snackbar.make(nestedScrollView, getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG).show();
    }
}

/**
 * This method is to empty all input edit text
 */
private void emptyInputEditText() {
    textInputEditTextEmail.setText(null);
    textInputEditTextPassword.setText(null);
    }
}

Navigation drawer:

      public class NavigationDrawer extends Activity {
      private DrawerLayout mDrawerLayout;
      private ActionBarDrawerToggle nToggle;
      private ActionBar supportActionBar;

        @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    nToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
    mDrawerLayout.addDrawerListener(nToggle);
    nToggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem items){
    if(nToggle.onOptionsItemSelected(items)) {
        return true;
    }
        return super.onOptionsItemSelected(items);
    }

public ActionBar getSupportActionBar() {
    return supportActionBar;
}
}

}

How can I fix this?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
M. Umer
  • 11
  • 5

1 Answers1

0

There are following issues:

  1. Developer did not initialize name second activity in manifest file.

  2. Did not use "this" in second activity for getting getsupportActionBar()