Aller au contenu

[résolu] Lancer une activity selon le choix dans une ListView


Picool

Recommended Posts

Bonjour à tous,

J'ai un petit soucis en ce moment c'est que mon application plante quand je clique sur un objet de ma listview...Le but que je cherche à obtenir c'est qu'en "cliquant" sur un élément de ma listView cela lance une autre activité (qui est une nouvelle listView).

Je pense que l'erreur vient du choix pour appeler l'activity :

      maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
       	   public void onItemClick(AdapterView<?> a, View v, int position, long id) {
       	    CallFunc(position);
       	}

		private void CallFunc(int position) {
			Intent intent = getIntent();
        	switch (position) {
        	  case 0:
        	    intent = new Intent(getBaseContext() , Tricks.class);
        	  break;
        	  case 1 :
        	   intent = new Intent(getBaseContext() , Mods.class);
        	  break;
        	  case 2 :
        		  intent = new Intent (getBaseContext () , Combos.class);
        	break;
        	  case 3 :
        		  intent = new Intent (getBaseContext () , Videos.class);

        	}
        	if(intent != null)
        	    startActivity(intent);
		}

Eclipse ne me signale aucun soucis et compile sans problèmes, et j'arrive à lancer l'appli mais au click ça plante...

Pouvez m'aider svp ?

Merci

Lien vers le commentaire
Partager sur d’autres sites

T'aurais pas oublier de déclarer l'Activity que tu lances dans le androidManifest.xml ?

Elles sont bien déclarés dedans :

       <activity android:name=".Tricks"
                 android:label="@string/app_name">
           <intent-filter>
               <action android:name="android.intent.action.listetricks" />
               <category android:name="android.intent.category.LAUNCHER" />
               </intent-filter>
               </activity>
                       <activity android:name=".Mods"
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar">
           <intent-filter>
               <action android:name="android.intent.action.listemods" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
               <activity android:name=".Combos"
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar">
           <intent-filter>
               <action android:name="android.intent.action.listecombos" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
               <activity android:name=".Videos"
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar">
           <intent-filter>
               <action android:name="android.intent.action.listevideos" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>

Lien vers le commentaire
Partager sur d’autres sites

03-03 21:46:32.294: INFO/ActivityManager(33): Start proc com.penspinning for activity com.penspinning/.PenSpinning: pid=245 uid=10030 gids={}
03-03 21:46:32.314: DEBUG/dalvikvm(234): LinearAlloc 0x0 used 638596 of 5242880 (12%)
03-03 21:46:32.844: DEBUG/ddm-heap(245): Got feature list request
03-03 21:46:33.166: INFO/ARMAssembler(33): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x40dd40:0x40debc] in 9095623 ns
03-03 21:46:33.424: INFO/ARMAssembler(33): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x40dec0:0x40dfcc] in 1201561 ns
03-03 21:46:34.594: INFO/ActivityManager(33): Displayed activity com.penspinning/.PenSpinning: 2461 ms (total 2461 ms)
03-03 21:46:34.774: INFO/ARMAssembler(33): generated scanline__00000077:03545404_00000A04_00000000 [ 29 ipp] (51 ins) at [0x40dfd0:0x40e09c] in 10141150 ns
03-03 21:46:39.594: INFO/ActivityManager(33): Starting activity: Intent { cmp=com.penspinning/.Tricks }
03-03 21:46:39.754: DEBUG/AndroidRuntime(245): Shutting down VM
03-03 21:46:39.754: WARN/dalvikvm(245): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-03 21:46:39.769: ERROR/AndroidRuntime(245): Uncaught handler: thread main exiting due to uncaught exception
03-03 21:46:39.804: ERROR/AndroidRuntime(245): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.penspinning/com.penspinning.Tricks}: java.lang.NullPointerException
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.os.Looper.loop(Looper.java:123)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at java.lang.reflect.Method.invokeNative(Native Method)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at java.lang.reflect.Method.invoke(Method.java:521)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at dalvik.system.NativeStart.main(Native Method)
03-03 21:46:39.804: ERROR/AndroidRuntime(245): Caused by: java.lang.NullPointerException
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at com.penspinning.Tricks.onCreate(Tricks.java:22)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-03 21:46:39.804: ERROR/AndroidRuntime(245):     ... 11 more
03-03 21:46:39.859: INFO/Process(33): Sending signal. PID: 245 SIG: 3
03-03 21:46:39.864: INFO/dalvikvm(245): threadid=7: reacting to signal 3
03-03 21:46:39.924: INFO/dalvikvm(245): Wrote stack trace to '/data/anr/traces.txt'
03-03 21:46:43.474: INFO/Process(245): Sending signal. PID: 245 SIG: 9
03-03 21:46:43.544: INFO/ActivityManager(33): Process com.penspinning (pid 245) has died.
03-03 21:46:43.554: INFO/WindowManager(33): WIN DEATH: Window{43dcfd78 com.penspinning/com.penspinning.PenSpinning paused=false}
03-03 21:46:43.644: INFO/ActivityManager(33): Start proc com.penspinning for activity com.penspinning/.PenSpinning: pid=251 uid=10030 gids={}
03-03 21:46:44.054: DEBUG/ddm-heap(251): Got feature list request
03-03 21:46:44.185: INFO/UsageStats(33): Unexpected resume of com.penspinning while already resumed in com.penspinning
03-03 21:46:44.214: INFO/ActivityManager(33): Displayed activity com.penspinning/.PenSpinning: 660 ms (total 4522 ms)

Le logcat des erreurs s'affiche pas quand je test avec mon tel en debug ^^ (la c'est VM)

EDIT : j'ai finalement trouvé mon erreur ! Merci d'avoir essayé de m'aider ça m'a permis de tout de même arrivé à la fin (le soucis était un setContentView(R.layout.xxxx mal renseigné)

Lien vers le commentaire
Partager sur d’autres sites

Essaye en faisant ça:


maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                   CallFunc(position);
               }

                       private void CallFunc(int position) {

                       switch (position) {
                         case 0:
                           Intent intent = new Intent(LeNomDeActivity.this , Tricks.class);
                           startActivity(intent);
                         break;

                         case 1 :
                          Intent intent = new Intent(LeNomDeActivity.this , Mods.class);
                          startActivity(intent);
                          break;

                         case 2 :
                          Intent intent = new Intent (LeNomDeActivity.this , Combos.class);
                          startActivity(intent);
                          break;

                         case 3 :
                          Intent intent = new Intent (LeNomDeActivity.this , Videos.class);
                          startActivity(intent);
                          break;

                       }
                       }

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...