Error in android attempt

0

I have created a very simple attempt that by clicking on a button with onClick() leads to another Activity :

public void ejecutarInfo(View view){
        Intent intento = new Intent(this, InfoClass.class);

        startActivity(intento);
}

Error exiting:

the onclick atribute value should be the name of a method in this
views context to invoke the  view when is clicked

and it tells me that the method must have a view of what it has.

Thanks. =)

    
asked by AGOI 15.10.2018 в 21:12
source

2 answers

0

The error is that you are inflating the view of info.xml, you should inflate activy_main.xml.

In your MainActivity.java should be more or less like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
}
    
answered by 16.10.2018 / 13:52
source
0

According to the message, the method is not in the same class Activity that the button clicks on!

The class Activity must contain the method that must be called from the button that loads the layout, the button calls the method from the attribute android:onClick :

android:OnClick="ejecutarInfo"

Ensure that the Activity that the layout containing the button loads, has the ejecutarInfo() method.

    
answered by 15.10.2018 в 23:15