Good morning, I'm practicing with AndroidStudio and I want to make an app with several activities
, the case is that from the main to the second happens perfectly but from this second to the rest the application closes with the following error:
java.lang.IllegalStateException: Could not find method onStatistics (View) in a parent or ancestor Context for android: onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'Statistics'
I have tried several things but I do not give with the key, currently I am only linking a button (Statistics) to the method, the rest will be the same :( I have tested with intent
as well)
MenuPrincipal Class:
package raulredondo.macesmanager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SearchView;
public class MenuPrincipal extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_principal);
}
public void onEstadisticas(View view){
setContentView(R.layout.activity_estadisticas);
}
}
activity_menu_principal.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="raulredondo.macesmanager.MenuPrincipal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="200dp"
android:orientation="vertical"
android:weightSum="1"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/plantilla"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Plantilla" />
<Button
android:id="@+id/Estadisticas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onEstadisticas"
android:text="Estadisticas" />
<Button
android:id="@+id/Eventos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onEventos"
android:text="Eventos" />
<Button
android:id="@+id/convocatoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Convocatoria" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="205dp"
android:orientation="horizontal"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="11dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="11dp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="16dp"
app:layout_constraintLeft_toLeftOf="parent">
<TextView
android:id="@+id/proxPartidoMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom|center_horizontal"
android:text="Próximo partido:"
android:textSize="30sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>