【发布时间】:2013-09-28 21:47:03
【问题描述】:
我将二维数组 [][] 对象作为额外的意图传递给另一个活动,但它的显示错误我无法识别我该怎么办?
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[0][i]);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(l);
【问题讨论】:
-
l.putExtra("msg",xmlResponse2[0][i]);此行显示错误
-
它超出了我的范围,你不能在那里使用我
-
那么我如何将 xmlResponse2[0][i] 值作为参数传递给另一个活动?
-
你的 i 是在 for 循环中声明的,所以它的作用域以 for 循环结束,不能在外面使用它
-
不要以这种方式使用,只需像 xmlResponse2 一样传递整个数组,然后通过放入一个循环得到你想要的@另一边