First of all, I'm an absolute beginner when it comes to Java and Android Studio. I am creating a simple app and am trying to implement activity switching with animations. However, something seems to be causing the app to crash before it even opens on my phone or any virtual device. I am (pretty) sure the onClick() is not causing it.
/*home.java*/
package com.example.memorygame;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class home extends AppCompatActivity {
ImageButton ibNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
ibNext=(ImageButton) findViewById(R.id.ibNext);
ibNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(home.this, start.class));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_out);
}
});
}
}
/*start.java*/
package com.example.memorygame;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class start extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
}
}
CodePudding user response:
Because you did a refactoring of the name of your main activity, it's most probably because you did not change the name in your manifest.
Check this link about how you register an activity in your manifest file.
Don't forget to declare action android.intent.action.MAIN
and category android.intent.category.LAUNCHER
for your main activity (the one shown after launching the app), as shown in the example at the bottom of the page.
If this is not causing your problem search for the old name in the entire application (CTRL SHIFT F).