1

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.

1
  • Ok, thank you, these methods works as well. It turns out, I was actually being careless and had a non-related logic error further back in my code resulting in the posted problem. Thank you for your help, and sorry for posting too rapidly. Commented Oct 9, 2011 at 5:14

2 Answers 2

1

Incase of Class A

i.putExtra("input",inputArr); 

In case of Class B

Bundle extras = getIntent().getExtras();
int arrayB = extras.getStringArray("numbers"); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try

String[] myStrings = getIntent().getStringArray("input");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.