I am creating an app where you log in and then access a database of files unique to each user account. I have a continue button linking the "LoginActivity" and "MainActivity" activities together. The code that I have in the LoginActivity file is this:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.email_create_account_button:
createAccount(mEdtEmail.getText().toString(), mEdtPassword.getText().toString());
break;
case R.id.email_sign_in_button:
signIn(mEdtEmail.getText().toString(), mEdtPassword.getText().toString());
break;
case R.id.sign_out_button:
signOut();
break;
case R.id.continue_button:
Button btn = (Button)findViewById(R.id.continue_button);
startActivity(new Intent(LoginActivity.this, MainActivity.class));
break;
}
}
and on the MainActivity side I have this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
upload_button = findViewById(R.id.upload_button);
showall_button = findViewById(R.id.showall_button);
progressBar = findViewById(R.id.progressBar);
imageView = findViewById(R.id.imageView);
progressBar.setVisibility(View.INVISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent , 2);
}
});
What is wrong with my code? I can’t seem to figure it out. Please let me know if you need more code from my project. Thanks!
2
Answers
You should initialize your buttons and after that, set onclicklistener to them. For the complete explanation visit Android App Crashes on Button Click
According to your logcat, it seems that, you are referencing an resource ID which doesn’t exists on your XML (
activity_main.xml
) file.Check whether the ID
imageView
exists or not. It might not present in your layout file or it may have different name. Make the ID name same both inactivity_main.xml
side andMainActivity
side.