2011-07-25 5 views
1

Si vous tentez d'envoyer un message texte plus de 100 fois, y a-t-il un moyen de remplacer la limitation de texte SMSDispatcher?Application Android force close

est ici l'erreur:

08-02 03:34:07.927: WARN/dalvikvm(1199): threadid=1: thread exiting with uncaught  exception (group=0x4001d800) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): FATAL EXCEPTION: main 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): java.lang.NullPointerException 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at com.android.internal.telephony.SMSDispatcher.handleReachSentLimit(SMSDispatcher.java:809) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:339) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at android.os.Looper.loop(Looper.java:123) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at java.lang.reflect.Method.invoke(Method.java:521) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
08-02 03:34:07.927: ERROR/AndroidRuntime(1199):  at dalvik.system.NativeStart.main(Native Method) 

Voici mon code - mise à jour:

import java.util.Random; 
import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

public class MainActivity extends Activity { 
EditText PhNumber, Message, TxtCount; 
Button btnSendSMS; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);   

    //create text box to enter phone number 
    PhNumber=(EditText) findViewById(R.id.PhNumber);   
    //create text box to enter message 
    Message=(EditText) findViewById(R.id.Message);   
    //create text box to see how many times the user wants to send message 
    TxtCount=(EditText) findViewById(R.id.TxtCount); 
    //create button to send text message 
    btnSendSMS = (Button) findViewById(R.id.btnSendSMS); 
    //create listener for button 
    btnSendSMS.setOnClickListener(new View.OnClickListener() 

    {    
     public void onClick(View v) 
      {   
       //variable for count. 
       int count = 1; 
       //variable for text message 
       String msg = Message.getText().toString(); 
       //create string array of the alphabet 
       String[] mArray = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
         "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "r", "x", "y", "z"}; 
       //create variable to hold random number 
       final Random r = new Random(); 
       //variable for phone number 
       String num = PhNumber.getText().toString(); 
       //create array of the phone number to get the number of numbers entered. 
       char[] nArray = num.toCharArray(); 
       //variable for the amount of text messages to send. 
       String max1 = TxtCount.getText().toString(); 
       //variable to watch button and hide keyboard 
       InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       //test to see if number has a value 
       if (num.equals("") || (nArray.length < 10)) 
       { 
        Toast.makeText(getApplicationContext(), "Enter 10 digit phone number!", Toast.LENGTH_SHORT).show(); 
        return; 
       } 
       //test to see if msg has a value 
       if (msg.equals("")) 
       { 
        Toast.makeText(getApplicationContext(), "Enter a message!", Toast.LENGTH_SHORT).show(); 
        return; 
       }   
       //test to see if there's a number of times to text 
       if (max1.equals("") || (Integer.parseInt(TxtCount.getText().toString()) <= 0)) 
       { 
        Toast.makeText(getApplicationContext(), "Enter a number more than zero to nuke!", Toast.LENGTH_SHORT).show(); 
        return; 
       }    
       //if all fields have valid data -- send text message until count = max 
       int max = Integer.parseInt(TxtCount.getText().toString()); 
       while (count <= max) { 
        //create variable to hold random letter of the alphabet 
        String rLetter = mArray[r.nextInt(25)]; 
        String rLetter2 = mArray[r.nextInt(25)]; 
        String rLetter3 = mArray[r.nextInt(25)]; 
        String rLetter4 = mArray[r.nextInt(25)]; 
        final Random i = new Random(); 
        sendSMS(num, (rLetter3 + i.nextInt(100) + rLetter4 + " " + msg + " " + rLetter + i.nextInt(100) +rLetter2)); 
        count++; 
       }; 
       //hide the keyboard 
       mgr.hideSoftInputFromWindow(TxtCount.getWindowToken(), 0); 
       mgr.hideSoftInputFromWindow(PhNumber.getWindowToken(), 0); 
       mgr.hideSoftInputFromWindow(Message.getWindowToken(), 0); 
       //set phone number to "" 
       PhNumber.setText(""); 
       //set message to "" 
       Message.setText(""); 
       //set count to "" 
       TxtCount.setText(""); 
       //refocus on phone number 
       PhNumber.requestFocus();      
      }   
    });   
} 
//sends a sms message to another device 
private void sendSMS(String phoneNumber, String message) 
    {  
     SmsManager sms = SmsManager.getDefault(); 
     sms.sendTextMessage(phoneNumber, null, message, null, null); 
    } 
} 
+0

bien il donnera exception à ces lignes si (TxtCount.getText(). ToString() == "") else if (num == "") else if (msg == "") A chaîne doit être vérifiée avec equalIgnoreCase (""); le changer et voir le résultat –

+0

Postez votre trace de pile s'il vous plaît. – Reno

Répondre

0

Vous ne pouvez pas comparer avec chaîne == essayer

if (TxtCount.getText().toString().equals("")) 
{ 
    Toast.makeText(getApplicationContext(), "Please enter a number of times to nuke!", Toast.LENGTH_SHORT).show(); 
} 
else if (num.queals("")) 
{ 
    Toast.makeText(getApplicationContext(), "Please enter a phone number to nuke!", Toast.LENGTH_SHORT).show(); 
} 
else if (msg.equals("")) 
{ 
    Toast.makeText(getApplicationContext(), "Please enter a message!", Toast.LENGTH_SHORT).show(); 
} 

while (count <= max) 
{     
    sendSMS(""+num,""+ msg); 
    count++; 
}; 

Vous aimez cette

else if (num.equals("")) 
{ 
    Toast.makeText(getApplicationContext(), "Please enter a phone number to nuke!", Toast.LENGTH_SHORT).show(); 
    return; 
} 
+0

C'est vrai, mais ce n'est pas le problème qui force la fermeture de l'application. Il y a une exception NullPointerException quelque part –

+0

Toujours en train de fermer une force. Aucun de mes toasts ne montre – Android

+0

Il doit vérifier son fichier de mise en page lors de l'accès par findViewById.Je suppose qu'il a foiré l'orthographe – Rasel

Questions connexes