Desarrollo de Android en eclipse: la actividad 1 cambia a la actividad 2 bien, no 3

Lo siento por mi mal ingles, hablo francés. Estoy tratando de hacer una aplicación sencilla con 4 actividades. En el primero (MainActivity), si hago clic en el botón "buscar", cambia a la segunda actividad (RechercherActivity). Entonces puedo volver a MainActivity.

En MainActivity, puedo hacer clic en 3 botones ("rechercher", "trouvez" y "liste"). El primero funciona bien, pero no los otros dos, aunque los he creado de la misma manera. "RechercherActivity" fue el primero de los 3 que he hecho.

Cuando hago clic en "trouvez" o "liste", me sale "la aplicación dejó de funcionar" mensaje de error, y esto es lo que aparece en LogCat: Los problemas comienzan en la segunda línea.

introduzca la descripción de la imagen aquí

package com.example.jouons; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupTrouvezButton(); setupRechercherButton(); setupListeButton(); } private void setupListeButton() { Button listeButton = (Button) findViewById(R.id.btnMainListe); listeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(MainActivity.this, ListeActivity.class)); } }); } private void setupTrouvezButton() { Button trouvezButton = (Button) findViewById(R.id.btnMainTrouvez); trouvezButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(MainActivity.this, TrouvezActivity.class)); } }); } private void setupRechercherButton() { Button rechercherButton = (Button) findViewById(R.id.btnMainRechercher); rechercherButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(MainActivity.this, RechercherActivity.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

y

  package com.example.jouons; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class RechercherActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rechercher); setupRetourButton(); } private void setupRetourButton() { Button retourButton = (Button) findViewById(R.id.btnRechercherRetour); retourButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(RechercherActivity.this, MainActivity.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.rechercher, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

y

  package com.example.jouons; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class TrouvezActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_trouvez); setupRetourButton(); } private void setupRetourButton() { Button retourButton = (Button) findViewById(R.id.btnRechercherRetour); retourButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(TrouvezActivity.this, MainActivity.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.trouvez, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

y

  package com.example.jouons; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class ListeActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_liste); setupRetourButton(); } private void setupRetourButton() { Button retourButton = (Button) findViewById(R.id.btnRechercherRetour); retourButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(ListeActivity.this, MainActivity.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.liste, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

y

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jouons" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".RechercherActivity" android:label="@string/title_activity_rechercher" > </activity> <activity android:name=".TrouvezActivity" android:label="@string/title_activity_trouvez" > </activity> <activity android:name=".ListeActivity" android:label="@string/title_activity_liste" > </activity> </application> </manifest> 

¡Gracias!

Debe anular el método onClick dentro de OnClickListener.

 private void setupListeButton() { Button listeButton = (Button) findViewById(R.id.btnMainListe); listeButton.setOnClickListener(new View.OnClickListener() { @Override // this is what you are forgetting public void onClick(View v) { startActivity(new Intent(MainActivity.this, ListeActivity.class)); } }); } 

Utilice id diferente para diferentes botones. Si se está desarrollando con eclipse, se supone que se obtiene error de tiempo de compilación para los botones que ha utilizado id mismo.

  • Preload de imágenes múltiples con Glide
  • Texto diferente para cada imagen en el visor de imágenes
  • Optimización de la aplicación de Android antes del lanzamiento
  • La notificación de Android no muestra su contenido cuando la aplicación no se está ejecutando
  • ¿Cuál es el propósito claro de SparseBooleanArray ??
  • ¿Cómo deshacerse de la advertencia de llamada sospechosa en Android Studio?
  • ¿Cuál es la diferencia entre View.postDelayed () y Handler.postDelayed () en el hilo principal?
  • Cómo configurar canOverrideExistingModule = true
  • Elementos de menú de la bandeja de navegación seleccionados dentro de diferentes grupos
  • Android cursor cómo obtener valores nulos de columnas
  • ¿Cómo puedo hacer que el botón "Arriba" de mi ActionBar funcione como el botón "Atrás" del teléfono?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.