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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:58:21+00:00 2026-06-17T04:58:21+00:00

I have an Rss feed that I have parsed in one activity. Each item

  • 0

I have an Rss feed that I have parsed in one activity. Each item has a seperate url attached to it. When an item is clicked in the listview it opens into another activity displaying specific text that i have defined from the xml that is being parsed. I have a button in that view that i would like to assign the url from the xml file for that item. The only thing i can’t figure out is how to string the url information to that button. here is the code i’m using.

xml parsing activity

public class AndroidXMLParsingActivity extends ListActivity {

// All static variables
static final String URL = "http://www.cpcofc.org/devoapp.xml";
// XML node keys
static final String KEY_ITEM = "item"; // parent node
static final String KEY_ID = "item";
static final String KEY_NAME = "title";
static final String KEY_COST = "description";
static final String KEY_DESC = "description";
static final String KEY_GUID = "guid";
static final String KEY_LINK = "link";

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_ITEM);
    // looping through all item nodes <item>
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);
        // adding each child node to HashMap key => value
        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
        map.put(KEY_COST, parser.getValue(e, KEY_COST));
        map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
        map.put(KEY_GUID, parser.getValue(e, KEY_GUID));
        map.put(KEY_LINK, parser.getValue(e,KEY_LINK));


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

    // Adding menuItems to ListView
    ListAdapter adapter = new SimpleAdapter(this, menuItems,
            R.layout.list_item,
            new String[] { KEY_DESC, KEY_NAME, KEY_COST, KEY_GUID}, new int[] {
                    R.id.desciption, R.id.name, R.id.cost});

    setListAdapter(adapter);

    Collections.reverse(menuItems);

    // selecting single ListView item
    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
            String cost = ((TextView) view.findViewById(R.id.cost)).getText().toString();
            Uri uriUrl = Uri.parse(menuItems.get(position).get(KEY_GUID));

            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
            in.putExtra(KEY_NAME, name);
            in.putExtra(KEY_COST, cost);
            in.putExtra(KEY_GUID, uriUrl);
            startActivity(in);

        }
    });
}
 }

Second activity that has the button to view url in it

public class SingleMenuItemActivity  extends Activity {

// XML node keys
static final String KEY_NAME = "title";
static final String KEY_COST = "description";
static final String KEY_DESC = "description";
static final String KEY_GUID = "guid";


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);

    // getting intent data
    final Intent in = getIntent();

    // Get XML values from previous intent
    String name = in.getStringExtra(KEY_NAME);
    String cost = in.getStringExtra(KEY_DESC);
    String description = in.getStringExtra(KEY_DESC);
    String uriUrl = in.getStringExtra(KEY_GUID);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);
    TextView lblCost = (TextView) findViewById(R.id.cost_label);
    TextView lblDesc = (TextView) findViewById(R.id.description_label);


    lblName.setText(name);
    lblCost.setText(cost);
    lblDesc.setText(description);

Button devo = (Button) findViewById(R.id.button1);
devo.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v){
        String url = "http://www.google.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);


    }
});
}

}

I think my problem lies in this part of the code

Button devo = (Button) findViewById(R.id.button1);
devo.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v){
        String url = "http://www.google.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);

but I’m not sure what to put here

String url = "what do i put here???";

to string the url from the item clicked in the previous screen

this is what the first screen looks like that parses the xml into a listview

enter image description here

Here is what happens when you click an item in the list view

enter image description here

log cat

01-13 15:14:31.818: E/AndroidRuntime(8665): FATAL EXCEPTION: main
01-13 15:14:31.818: E/AndroidRuntime(8665): java.lang.NullPointerException: uriString
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.net.Uri$StringUri.<init>(Uri.java:420)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.net.Uri$StringUri.<init>(Uri.java:410)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at  android.net.Uri.parse(Uri.java:382)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at com.androidhive.xmlparsing.SingleMenuItemActivity$1.onClick(SingleMenuItemActivity.java:51)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.view.View.performClick(View.java:2532)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.view.View$PerformClick.run(View.java:9293)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.os.Handler.handleCallback(Handler.java:587)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.os.Looper.loop(Looper.java:150)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at android.app.ActivityThread.main(ActivityThread.java:4263)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at java.lang.reflect.Method.invokeNative(Native Method)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at java.lang.reflect.Method.invoke(Method.java:507)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-13 15:14:31.818: E/AndroidRuntime(8665):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T04:58:22+00:00Added an answer on June 17, 2026 at 4:58 am

    You are trying to pass an Uri Object to a Bundle, a String represenation would be enough

    EDIT2:

     lv.setOnItemClickListener(new OnItemClickListener() {
    
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
            String cost = ((TextView) view.findViewById(R.id.cost)).getText().toString();
            Uri uriUrl = Uri.parse(menuItems.get(position).get(KEY_GUID));
    
            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
            in.putExtra(KEY_NAME, name);
            in.putExtra(KEY_COST, cost);
    
            // **NEED TO PASS STRING OBJECT NOT URI OBJECT**
            in.putExtra(KEY_GUID, uriUrl.toString());
            startActivity(in);
    
        }
    });
    

    EDIT:

    public class SingleMenuItemActivity  extends Activity {
    
    // XML node keys
    static final String KEY_NAME = "title";
    static final String KEY_COST = "description";
    static final String KEY_DESC = "description";
    static final String KEY_GUID = "guid";
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);
    
        // getting intent data
        final Intent in = getIntent();
    
        // Get XML values from previous intent
        String name = in.getStringExtra(KEY_NAME);
        String cost = in.getStringExtra(KEY_DESC);
        String description = in.getStringExtra(KEY_DESC);
        final String uriUrl = in.getStringExtra(KEY_GUID);
    
        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblCost = (TextView) findViewById(R.id.cost_label);
        TextView lblDesc = (TextView) findViewById(R.id.description_label);
    
    
        lblName.setText(name);
        lblCost.setText(cost);
        lblDesc.setText(description);
    
    Button devo = (Button) findViewById(R.id.button1);
    devo.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v){
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(uriUrl));
            startActivity(i);
    
    
        }
    });
    }
    
    }
    

    OR

    public class SingleMenuItemActivity  extends Activity {
    
    // XML node keys
    static final String KEY_NAME = "title";
    static final String KEY_COST = "description";
    static final String KEY_DESC = "description";
    static final String KEY_GUID = "guid";
    
    private String url;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);
    
        // getting intent data
        final Intent in = getIntent();
    
        // Get XML values from previous intent
        String name = in.getStringExtra(KEY_NAME);
        String cost = in.getStringExtra(KEY_DESC);
        String description = in.getStringExtra(KEY_DESC);
        url= in.getStringExtra(KEY_GUID);
    
        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblCost = (TextView) findViewById(R.id.cost_label);
        TextView lblDesc = (TextView) findViewById(R.id.description_label);
    
    
        lblName.setText(name);
        lblCost.setText(cost);
        lblDesc.setText(description);
    
    Button devo = (Button) findViewById(R.id.button1);
    devo.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v){
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
    
    
        }
    });
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that has an Rss feed, and this feed is consumed
I have an RSS feed and I want to integrate each item into it
I have previsously parsed this RSS Feed, now that I have updated it to
I have a dynamically generated rss feed that is about 150M in size (don't
I have rss that has a number of other custom fields. do any of
SCENARIO: I have a simple application that checks its RSS feed and looks if
I have an Rss feed that i'm parsing. I need it to sort and
I have an application that reads an rss feed, parses the xml and adds
i have this rss feed to parse that contains several tags. i am able
I have a blog's RSS feed that I am trying to display on another

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.