Android应用程序强制关闭

Android应用程序强制关闭,android,sms,Android,Sms,尝试发送文本消息超过100次,是否有任何方法可以覆盖SMSDispatcher文本限制 以下是错误: 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:0

尝试发送文本消息超过100次,是否有任何方法可以覆盖SMSDispatcher文本限制

以下是错误:

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)
以下是我的代码-已更新:

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);
    }
}

不能将字符串与== 试试这个


如果TxtCount.getText.toString==else,如果num==else,如果msg==字符串必须用equalIgnoreCase检查,那么在这些行中会出现异常;请更改它并查看结果Post您的堆栈跟踪。没错,但这不是导致应用程序强制关闭的问题。在使用findViewById访问布局文件时,他必须检查布局文件。我猜他拼写有问题。你检查布局文件中视图的拼写了吗输入信息时一切正常只是在框中未输入任何内容时强制关闭。。好吧,如果你想发送的次数超过了一定的次数-是的,我所有的拼写都是正确的-你能发送没有电话号码的信息吗?
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++;
};
else if (num.equals(""))
{
    Toast.makeText(getApplicationContext(), "Please enter a phone number to nuke!", Toast.LENGTH_SHORT).show();
    return;
}