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 8849783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:44:35+00:00 2026-06-14T12:44:35+00:00

I have declared few integer values in an xml and need to use the

  • 0

I have declared few integer values in an xml and need to use the values in a Class to define the array size of an object.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--     Default Object Count -->
    <item format="integer" name="item1" type="integer">3</item>
    <item format="integer" name="item2" type="integer">1</item>
    <item format="integer" name="item3" type="integer">1</item>
</resources>

I am using above values in my class as follows

public class InitialiseObjects {
    // For now static number of objects initialized
    private String TAG = "INIT_OBJECTS";
    int ITEM1_COUNT = R.integer.item1;
    int ITEM2_COUNT = R.integer.item2;
    int ITEM3_COUNT = R.integer.item3;

    private Item1[] item1Objs = new Item1[ITEM1_COUNT];
    private Item2[] item2Objs = new Item2[ITEM2_COUNT];
    private Item3[] item3Objs = new Item3[ITEM3_COUNT];
}

I expect ITEM*_COUNT to be 3,1,1 respectively for items 1,2,3.
However I get 2131034112, 2131034113, 2131034114 respectively

What’s wrong here ?

Android 2.2 [API-8] is being used

  • 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-06-14T12:44:36+00:00Added an answer on June 14, 2026 at 12:44 pm

    R.integer.item1 is the ID of the resource, and thus a very big and arbitrary integer.

    The value your looking for is getContext().getResources().getInteger(R.integer.item1);

    Thus, you won’t be able to get them in a static code.

    You should use lazy initialization in your code :

    private Item1[] item1Objs;
    public Item1[] getItem1Array(Context context) {
      if (item1Objs == null) {
         int count = context.getResources().getInteger(R.integer.item1);
         item1Objs = new Item1[count];
         }
      return item1Objs;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few global methods declared in public class in my ASP.NET web application.
I have a class that offers up a few events. That class is declared
I have declared the following type KEY = (IPv4, Integer) type TPSQ = TVar
I have declared an array in the form: var refs = { 'EE810': Presence
I have developed a custom visual basic 6 control and declared a few custom
I have a class that starts a few threads. Each thread (extends Thread) calls
In my project I have a few declared enums. I would like to create
I have written a few Android apps, and have always declared a starting Activity
When we say we have declared our form bean in session scope, few questions
I have an asp.net web service project. This project contains a few classes declared

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.