This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

array decleration in an string  RSS feed

Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have declared the values in string but is hows some error like this "array cannot be resolved or is not a field"
in code String[] testArray = getResources().getStringArray(R.array.testArray);


import android.os.Bundle;
import android.widget.ArrayAdapter;

public class Episode7 extends ListActivity {
String[] testArray = getResources().getStringArray(R.array.testArray);

/** Called when the activity is first created. */
protected void onCreate(Bundle savedInstanceState) {


// Create an ArrayAdapter that will contain all list items
ArrayAdapter<String> adapter;

/* Assign the name array to that adapter and
also choose a simple layout for the list items */
adapter = new ArrayAdapter<String>(

// Assign the adapter to this ListActivity


main.xml in this i get an error " android:text="@string/hello" />" like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
androidrientation="vertical" >

android:text="@string/hello" />


string.xml is

<?xml version="1.0" encoding="utf-8"?>
<array name="testArray">

how to solve this ?
Ranch Hand
Posts: 38
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you are using wrong tag in the string.xml file. Enclose all your <item> within <string-array> tag and then give a try.

P.S : Kindly post all your code within the code tag.
Maybe he went home and went to bed. And took this tiny ad with him:
Thread Boost - a very different sort of advertising
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!