-1

这是我的应用程序代码,下面的 nto 意图部分我使用调试我发现不在行 xmlResponse2[0][i]=test[i]; 之后 我错了??任何人都可以帮助我在 xmlResponse2[0][i]=test[i]; 之后没有启动任何活动和代码中断 这条线

  public void onReceive(Context context, Intent intent) 
{
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";  

    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
            str += "SMS from " + msgs[i].getOriginatingAddress();                     
            str += " :";
            str += msgs[i].getMessageBody().toString();
            str += "\n";  



        String[][] xmlResponse2= null;
        String[] test = str.split("\n");
        xmlResponse2= new String[0][test.length];
        for (int i = 0; i < test.length; i++) {
            xmlResponse2[0][i]=test[i];
             Intent l = new Intent(context,AgAppMenu.class);
             l.putExtra("msg",xmlResponse2);
             l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
             context.startActivity(l);
        }

        //---display the new SMS message---
        Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
4

2 回答 2

0

这个说法:

xmlResponse2= new String[0][test.length];

创建一个包含 0 个元素的数组(即:没有元素)。也许您想创建一个包含 1 个元素的数组,如下所示:

xmlResponse2= new String[1][test.length];
于 2012-09-03T13:12:20.610 回答
0
 xmlResponse2= new String[test.length];
    for (int i = 0; i < test.length; i++) {
        xmlResponse2[i]=test[i];

    }
       Intent l = new Intent(context,AgAppMenu.class);
         l.putExtra("msg",xmlResponse2);
        // l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
         context.startActivity(l);
于 2012-09-03T13:12:33.997 回答