2012-11-06 2 views
0

Voici mon code:Force Close pour faire AlertDialog et DialogInterface

btnSendSMS.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      final String phoneNo = txtPhoneNo.getText().toString(); 

      final String message = '\u00AB' + "smsmks" + '\u00BB' + ' ' 
        + txtMessage.getText().toString(); 
      if ((phoneNo.length() > 0) && (message.length() > 0)) { 
       //pilihan, mengirim citra gambar atau tidak 
       final CharSequence[] items = { "Text", "Image" }; 
       AlertDialog.Builder kk = new AlertDialog.Builder(getBaseContext()); 
       kk.setTitle("Pilih Metode Penginputan"); 
       kk.setItems(items, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int x) { 
         Intent i = null; 
         if ("Text".equals(items[x])) { 
          sendSMS(phoneNo, message); 
          Toast.makeText(getBaseContext(), phoneNo, 
            Toast.LENGTH_SHORT).show(); 

         } else { 
          i = new Intent(TulisPesanLontara.this, 
            KonversiGambar.class); 
          startActivity(i); 
         } 
        } 
       }).show(); 

      } else 
       Toast.makeText(getBaseContext(), 
         "Please enter both phone number and message.", 
         Toast.LENGTH_SHORT).show(); 
     } 
    } 

Aucune erreur n'a été détectée, mais si je cours, et je clique sur les objets, je Approcher la force. Pouvez-vous m'aider? Merci les gars (désolé mauvais anglais)

Voici mon logcat

11-06 15: 48: 27,658: D/FastDelete (5657): ============= fin à une procédure delete event =========================== 11-06 15: 48: 28.307: I/fastDelete (5657): !!! La phase fastDelete s'est terminée !!! 11-06 15: 48: 30.371: D/AndroidRuntime (5657): Arrêt de la machine virtuelle 11-06 15: 48: 30.371: W/dalvikvm (5657): threadid = 1: thread sortant avec une exception non interceptée (groupe = 0x40020648) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): FATAL EXCEPTION: principal 11-06 15: 48: 30.373: E/AndroidRuntime (5657): android.view.WindowManager $ BadTokenException: Impossible d'ajouter fenêtre - jeton null n'est pas pour une application 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.view.ViewRoot.setView (ViewRoot.java:568) 11-06 15:48: 30.373: E/AndroidRuntime (5657): à android.view.WindowManagerImpl.addView (WindowManagerImpl.java:209) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à l'adresse android.view.WindowManagerImpl.addView (WindowManagerImpl.java:123) 11-06 15: 48: 30.373: E/AndroidRu ntime (5657): at android.app.Dialog.show (Dialog.java:272) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.app.AlertDialog $ Builder.show (AlertDialog. java: 849) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à com.ariefspekta.smsmakassar.TulisPesanLontara $ 4.onClick (TulisPesanLontara.java:177) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.view.View.performClick (View.java:2535) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.view.View $ PerformClick.run (Voir .java: 9130) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à l'adresse android.os.Handler.handleCallback (Handler.java:618) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.os.Handler.dispatchMessage (Handler.java:123) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à android.os.Looper.loop (fichier Source: 35 1) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à l'adresse android.app.ActivityThread.main (ActivityThread.java:3850) 11-06 15: 48: 30.373: E/AndroidRuntime (5657) : à java.lang.reflect.Method.invokeNative (méthode native) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à java.lang.reflect.Method.invoke (Method.java:538) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:901) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:659) 11-06 15: 48: 30.373: E/AndroidRuntime (5657): à dalvik.system.NativeStart.main (natif Méthode) 11-06 15: 48: 37.789: I/Process (5657): Signal d'envoi. PID: 5657 SIG: 9

+0

s'il vous plaît ajouter votre logcat – thepoosh

+0

http://stackoverflow.com/a/13245127/ 1487822 –

+0

Avez-vous ajouté KoversiGamber.class à votre manifeste? –

Répondre

0

Remplacez simplement getBaseContext() par getApplicationContext() ou utilisez ActivityName.this.

0

passent juste la référence de l'utilisation de l'application toute getApplicationContext() au lieu de getBaseContext, parce getBaseContext prendre référence activité particulière ..