"L'application s'est arrêté" dès que je cliques sur un bouton
guineeguinee
Messages postés
212
Statut
Membre
-
BunoCS Messages postés 16550 Date d'inscription Statut Modérateur Dernière intervention -
BunoCS Messages postés 16550 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
Je développe une application Android de Quizz avec Android Studio, j'ai utilisé un textview pour la question, trois boutons pour les choix de réponse, quand j'installe mon app sur mon appareil physique ou je l'ouvre avec l'AVD, j'ai la première question qui s'affiche si je cliques sur n'importe lequel des boutons, l'application s'arrête.
Merci d'avance pour votre aide!
Je développe une application Android de Quizz avec Android Studio, j'ai utilisé un textview pour la question, trois boutons pour les choix de réponse, quand j'installe mon app sur mon appareil physique ou je l'ouvre avec l'AVD, j'ai la première question qui s'affiche si je cliques sur n'importe lequel des boutons, l'application s'arrête.
Merci d'avance pour votre aide!
A voir également:
- Volka pro 2 a cessé de fonctionner
- Desinstaller application sur windows - Guide
- Nommez une application d'appel vidéo ou de visioconférence - Guide
- Comment supprimer une application préinstallée sur android - Guide
- Bouton shift pc ✓ - Forum Jeux vidéo
- Comment lire un message supprimé sur whatsapp sans application - Guide
4 réponses
Hello (ça faisait longtemps, tiens ;) ),
Qu'as-tu dans les logs? Tu dois sûrement avoir un problème dans le onClickListener...
@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
The urgent is done, the impossible is underway. For miracles, provide for a delay...
Qu'as-tu dans les logs? Tu dois sûrement avoir un problème dans le onClickListener...
@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
The urgent is done, the impossible is underway. For miracles, provide for a delay...
Voici le message du Gradle Consle
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\USER\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2600Alpha1Library
:app:prepareComAndroidSupportAppcompatV72600Alpha1Library
:app:prepareComAndroidSupportConstraintConstraintLayout100Alpha7Library
:app:prepareComAndroidSupportSupportCompat2600Alpha1Library
:app:prepareComAndroidSupportSupportCoreUi2600Alpha1Library
:app:prepareComAndroidSupportSupportCoreUtils2600Alpha1Library
:app:prepareComAndroidSupportSupportFragment2600Alpha1Library
:app:prepareComAndroidSupportSupportMediaCompat2600Alpha1Library
:app:prepareComAndroidSupportSupportV42600Alpha1Library
:app:prepareComAndroidSupportSupportVectorDrawable2600Alpha1Library
:app:prepareComGoogleAndroidGmsPlayServicesAds1026Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite1026Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1026Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1026Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut1026Library
:app:prepareComGoogleAndroidGmsPlayServicesGass1026Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1026Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportTestEspressoEspressoCore222Library
:app:prepareComAndroidSupportTestEspressoEspressoIdlingResource222Library
:app:prepareComAndroidSupportTestExposedInstrumentationApiPublish05Library
:app:prepareComAndroidSupportTestRules05Library
:app:prepareComAndroidSupportTestRunner05Library
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
BUILD SUCCESSFUL
Total time: 18.58 secs
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\USER\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2600Alpha1Library
:app:prepareComAndroidSupportAppcompatV72600Alpha1Library
:app:prepareComAndroidSupportConstraintConstraintLayout100Alpha7Library
:app:prepareComAndroidSupportSupportCompat2600Alpha1Library
:app:prepareComAndroidSupportSupportCoreUi2600Alpha1Library
:app:prepareComAndroidSupportSupportCoreUtils2600Alpha1Library
:app:prepareComAndroidSupportSupportFragment2600Alpha1Library
:app:prepareComAndroidSupportSupportMediaCompat2600Alpha1Library
:app:prepareComAndroidSupportSupportV42600Alpha1Library
:app:prepareComAndroidSupportSupportVectorDrawable2600Alpha1Library
:app:prepareComGoogleAndroidGmsPlayServicesAds1026Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite1026Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1026Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1026Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut1026Library
:app:prepareComGoogleAndroidGmsPlayServicesGass1026Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1026Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportTestEspressoEspressoCore222Library
:app:prepareComAndroidSupportTestEspressoEspressoIdlingResource222Library
:app:prepareComAndroidSupportTestExposedInstrumentationApiPublish05Library
:app:prepareComAndroidSupportTestRules05Library
:app:prepareComAndroidSupportTestRunner05Library
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
BUILD SUCCESSFUL
Total time: 18.58 secs
Le voici
--------- beginning of crash
10-23 14:52:44.513 5445-5445/com.quizzfouta.gn E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.quizzfouta.gn, PID: 5445
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.quizzfouta.gn.Questions.getChoice1(Questions.java:26)
at com.quizzfouta.gn.Main2Activity.updateQuestion(Main2Activity.java:104)
at com.quizzfouta.gn.Main2Activity.access$400(Main2Activity.java:12)
at com.quizzfouta.gn.Main2Activity$1.onClick(Main2Activity.java:57)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
--------- beginning of crash
10-23 14:52:44.513 5445-5445/com.quizzfouta.gn E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.quizzfouta.gn, PID: 5445
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.quizzfouta.gn.Questions.getChoice1(Questions.java:26)
at com.quizzfouta.gn.Main2Activity.updateQuestion(Main2Activity.java:104)
at com.quizzfouta.gn.Main2Activity.access$400(Main2Activity.java:12)
at com.quizzfouta.gn.Main2Activity$1.onClick(Main2Activity.java:57)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Tu n'as pas besoin de tout copier! Il faut que tu apprennes à lire les logs!
Avec l'extrait suivant, tu as toutes les billes pour corriger:
Avec l'extrait suivant, tu as toutes les billes pour corriger:
--------- beginning of crash
10-23 14:52:44.513 5445-5445/com.quizzfouta.gn E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.quizzfouta.gn, PID: 5445
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.quizzfouta.gn.Questions.getChoice1(Questions.java:26)
at com.quizzfouta.gn.Main2Activity.updateQuestion(Main2Activity.java:104)
at com.quizzfouta.gn.Main2Activity.access$400(Main2Activity.java:12)
at com.quizzfouta.gn.Main2Activity$1.onClick(Main2Activity.java:57)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
J'ai bien regardé ces references dans le code, je ne comprends pas ce quoi le problème.
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.quizzfouta.gn.Questions.getChoice1(Questions.java:26)
Une piste de correction: https://openclassrooms.com/fr/courses/6173501-debutez-la-programmation-avec-java?archived-source=26832#/id/r-20926
En tout cas voici mon MainActivity.java
2. on ne compare pas des chaînes de caractères avec "==". Regarde .
3. tes 3 callback onClickListener sont identiques -> il faut factoriser pour minimiser les sources d'erreur