Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:26:15+00:00 2026-05-24T10:26:15+00:00

I am new to android development. I’m trying to have my string.xml file add

  • 0

I am new to android development. I’m trying to have my string.xml file add the string instead of hard coding the string in the .java file.

I’m using this android developer tutorial and copied and pasted the code to make sure there are no typos.

The problem I am having is when I enter R.array does not show up as an option. I am not really sure what is wrong. Here is the Java-code. I have put a // by the lines that is giving me trouble:

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class HelloListActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String[] countries = getResources().getStringArray(R.array.countries_array);
        //The R. does not offer array as an option
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));

        ListView lv =getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener(){
            public void onItemClick(AdapterView<?>parent, View view,
                    int posistion, long id){

            Toast.makeText(getApplicationContext(), ((TextView)view).getText(),
                    Toast.LENGTH_SHORT).show();
            }
        });

    }
}

and here is my strings.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="countries_array">
        <item>Bahrain</item>
        <item>Bangladesh</item>
        <item>Barbados</item>
        <item>Belarus</item>
        <item>Belgium</item>
        <item>Belize</item>
        <item>Benin</item>
    </string-array>
</resources>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:26:17+00:00Added an answer on May 24, 2026 at 10:26 am

    Go to Project -> Clean and then Rebuild. The R.java is not holding the resource you just added. EDIT: also make sure to import YourPackage.ProjectName.R;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android development, but I am trying to add admob to
As I am new to Android development, I have used SAX xml parsing in
I am completely new to android, and pretty much a Java newb. I have
I am new to Android development and i have been asked to create an
I am new for android development. I am trying read and write contacts to
I am new to Android development and I have a question regarding custom views
I am new to Android development so have been picking things up over the
Quite new to Android development and Java in general, so please excuse any amateur
I am new to Android Development and I am having trouble with my XML
I am New to Android Development.How to convert the Following string(5/31/2011) in to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.