检索传递的字符串数组元素 - Android
我相信我正确地将字符串数组从 A 类传递到 B 类,但是我在单独访问每个元素时遇到了一些麻烦。这是我的代码的总体视图。
String[] inputArr = new String[4];
//CLASS A=====================================
inputArr[0] = zero;
inputArr[1] = one;
inputArr[2] = two;
inputArr[3] = three;
Bundle bundle = new Bundle();
bundle.putStringArray("input",inputArr);
//CLASSB==================================================
Bundle bundle = this.getIntent().getExtras();
String[] myStrings = new String[4];
myStrings = bundle.getStringArray("input");
因此,如果正确传递了该参数,那么我将如何将 B 类中的各个字符串分配给传递数组中的元素?我已经尝试过:
String aStr = myStrings[0];
但是,这显示了错误消息 - “令牌“;”上的语法错误,此令牌后需要表达式。”在这种情况下使用这种方法是否错误?如果是这样,我应该使用什么?提前感谢您的帮助。
I believe I am passing a String array from Class A to Class B correctly, however I am having a bit of trouble accessing each element individually. Here is a general view of my code.
String[] inputArr = new String[4];
//CLASS A=====================================
inputArr[0] = zero;
inputArr[1] = one;
inputArr[2] = two;
inputArr[3] = three;
Bundle bundle = new Bundle();
bundle.putStringArray("input",inputArr);
//CLASSB==================================================
Bundle bundle = this.getIntent().getExtras();
String[] myStrings = new String[4];
myStrings = bundle.getStringArray("input");
So if this is correctly getting passed, then how would I go about assigning indivdual strings in Class B to the elements in the passed array? I have tried:
String aStr = myStrings[0];
However, this is showing the error message - "syntax error on token ";", Expression expected after this token." Is this the wrong method to use in this situation? If so, what should I be using? Thank you for your help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
A类情况
B类情况
Incase of Class A
In case of Class B
尝试
Try