-1

I want a button to open an activity class that sets a layout xml file. Everything is in order but the button doesn't work without the @Override method. With the @Override method I get this error:

The method onCreate1(Bundle) of type MainActivity must override or implement a supertype method.

    Button button;

    @Override
    public void onCreate1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from activity_main.xml
        setContentView(R.layout.activity_main);

        // Locate the button in activity_main.xml
        button = (Button) findViewById(R.id.MyButton);

        // Capture button clicks
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {

                // Start NewActivity.class
                Intent myIntent = new Intent(MainActivity.this,
                        NewActivity.class);
                startActivity(myIntent);
            }
        });
    }

The reason is I already have an @Override annotation for another method.

What I have tried:

  • Reading the tutorial on activities, multiple activities, and passing data between activities.

  • Solving the problem by editing the android manifest.

  • Creating a separate launch intent for the activity.

King
  • 256
  • 1
  • 11
  • 3
    Why is your method named `onCreate1`? – shmosel Mar 09 '15 at 06:12
  • What exactly you want to do on button pressed? – Dhrumil Shah - dhuma1981 Mar 09 '15 at 06:31
  • You either need more practice in object oriented languages with regards to inheritance and polymorphism or you need to understand Android's Activity life cycle more clearly. Your question is very vague and can't be understood. Please make sure to clarify what you want and don't understand exactly. – einschnaehkeee Mar 09 '15 at 07:29
  • You **can't** override a **non existing** Android method. Remove the `@Override` from onCreate1(), and call your method from within another one (possibly acll it at the end of your onCreate() method). – Phantômaxx Mar 09 '15 at 08:31
  • Why can't I just @Override the main method above this method? – King Mar 09 '15 at 11:32
  • You can only override **real** Android methods. And **onCreate1()** is NOT. – Phantômaxx Mar 09 '15 at 12:05

4 Answers4

2

If you want to use method with name onCreate1(), you need to remove @Override from it

Fahim
  • 12,198
  • 5
  • 39
  • 57
0

Change

@Override
public void onCreate1(Bundle savedInstanceState)

to

@Override
protected void onCreate(Bundle savedInstanceState)
Sanjeet A
  • 5,171
  • 3
  • 23
  • 40
0

You should call it the same as the function you want to Override.

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    somethingSomething();
}
0

Removed the @Override annotation as suggested. Renamed the onCreate1 method to onCreate. I want this question closed as well because I need to think further upon how to effectively solve this problem.

King
  • 256
  • 1
  • 11