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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:19:56+00:00 2026-06-05T16:19:56+00:00

I’m trying to pass an Int value pulled from a JSON String to reduce

  • 0

I’m trying to pass an Int value pulled from a JSON String to reduce code redundancy.

Within my JSON file, I have a string value in “resFile“. I store this string into TAG_RES_FILE where I want to pass it in a Bundle as an Int.

If you look in my code, you will see comment //TRY #1//. This works as expected but I need that Int to come from a variable that stores my TAG_RES_FILE. At comment //TRY #2// is just an example to what I want to function – obviously it does not. In the next line, I tried converting the tag string to a Int but this gives a runtime error of:

java.lang.NumberFormatException: Invalid int: “resFile”

I have even tried putting 0x7f060000 (from R.java) into the JSON String.

So my question is: How do I accomplish this? Am I on the right track or should I go about it a completely different way?

Thnx for your help and input – please show code examples in your answer.

JSON String Snippit:

[
    {
        "_id": "1",
        "label": "A Lable",
        "title": "Some Title",
        "description": "Bla, bla, bla",
        "containerID": "Some container id",
        "isRawRes": "boolean value here",
        "resFile": "R.raw.advisory_circulators_sort_list"
    }, {. . .
]

In my HashMap:

// Parse the string to a JSON object
        for (int i = 0; i < json.length(); i++) {
            JSONObject json_data = json.getJSONObject(i);

            // Storing each json item in variable
            String id = json_data.getString(TAG_ID);
            String label = json_data.getString(TAG_LABEL);
            String title = json_data.getString(TAG_TITLE);
            String description = json_data.getString(TAG_DISCR);
            String containerID = json_data.getString(TAG_FRAG_ID);
            String isRawRes = json_data.getString(TAG_IS_RAW_RES);
            String resFile = json_data.getString(TAG_RES_FILE);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put(TAG_ID, id);
            map.put(TAG_LABEL, label);
            map.put(TAG_TITLE, title);
            map.put(TAG_DISCR, description);
            map.put(TAG_FRAG_ID, containerID);
            map.put(TAG_IS_RAW_RES, isRawRes);
            map.put(TAG_RES_FILE, resFile);

            // adding HashList to ArrayList
            mList.add(map);
}

In my ListViews setOnItemClickListener:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    . . .

        final Bundle args = new Bundle();

//TRY #1//int rawRes = R.raw.advisory_circulators_sort_list; <--I NEED TO GET THIS IN FROM MY TAG!!
//TRY #2//int rawRes = TAG_RES_FILE; <-- TO SOMETHING LIKE THIS!!
        int passResFile = Integer.parseInt(TAG_RES_FILE);//<--THIS GIVES A NPE!!
        args.putInt("KEY_RES_FILE", passResFile);

        bolean isRawRes = true;
        args.putBoolean("KEY_IS_RAW_RES", isRawRes);

        // Delayed to improve animations
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                ListViewFragment lvf = new ListViewFragment();
                lcFT.replace(R.id.listContainer, lvf).commit();
                lvf.setArguments(args);
            }
        }, 300);
    }
  • 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-05T16:19:57+00:00Added an answer on June 5, 2026 at 4:19 pm

    Instead, just store advisory_circulators_sort_list as opposed to R.raw.advisory_circulators_sort_list. Then, to get the Integer identifier, use this method:

    int passResFile = getResources().getIdentifier( resFile, "raw", getPackageName() );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.