0

I have created a Java code for my Android App.

String[] MovieName=new String[]{};

for (int i = 0; i < 15; i++) 
{
MovieName[i]=movieAtt.getAttributeValue( "name" );  //Value coming from my XML
}

ListViewObject.setAdapter(new ArrayAdapter<String>(screen2.this,android.R.layout.simple_list_item_1 , MovieName));

This code throws an Exception. I think i am not inserting vaues properly inside Java String Array.

All i want is to have a variable like MovieName={"1","2", "3"} to feed into the ListView of my code.

This is not much helpful too : http://download.oracle.com/javase/6/docs/api/java/lang/String.html

1
  • Throwing which exception? Can you point it out? Commented Nov 16, 2011 at 7:30

3 Answers 3

3

You initialize an empty array.

Try this

String[] MovieName = new String[15];
Sign up to request clarification or add additional context in comments.

1 Comment

Working Great Guys. Wish i could add all of you three as answers.
3

Your initilizing an empty string array. That will give you an ArrayOutOfBoundException.

If you always have 15 entries you could initialize it to 15.

String[] MovieName=new String[15];

Otherwise you could create an ArrayList and convert it to an array after you filled it.

Comments

1

If number of elements in MovieName is constant, then you should initialise it as

String[] MovieName=new String[15];

Your current initialisation is equal to

String[] MovieName=new String[0];

1 Comment

I have a variable, that gives me children of XML. for that variable i need to run the loop. Trying it. Thanks.

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.