Issue
I am new to programming and I was making an app in Android Studio. I wanted to make several buttons open a new Activity, but when repeating the process for the other buttons it gave me this error.
There's my code:
public class MainActivity extends AppCompatActivity {
private Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.octubre);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openActivity2();
}
});
}
public void openActivity2() {
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
private Button button2;
public void onClick(View v) {
Intent startIntent = new Intent(MainActivity.this, Activity3.class);
startActivity(startIntent);
button2 = (Button) findViewById(R.id.aucas);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openActivity3();
}
});
}
public void openActivity3() {
Intent intent = new Intent(this, Activity3.class);
startActivity(intent);
}
}
Solution
You may have two redundant onCreate methods. Activity class should have only one onCreate method. Please remove the method 'public void onCreate(Bundle icicle)' from your code. The onCreate method shown on the above code hasn't any issue. So, you can leave it as it is. I hope this will solve your issue.
Answered By - senye
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.