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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:03:50+00:00 2026-06-08T02:03:50+00:00

The following code parses data from a xml web-service and should pass the selected

  • 0

The following code parses data from a xml web-service and should pass the selected Item’s data from list view to next activity.

The code works well until i click on the list item to pass data to the next activity but then the app crashes.

I have tried many fixes to solve the problems, like remove the setcontentView but still same.

 public class LastActivity extends ListActivity {
        /** Called when the activity is first created. */
        ListView lv;

    static String UName="name";
    static String UniUrl="description";
    public String val;
    static List<String> links;
    static List<String> names;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        lv=(ListView) findViewById(R.id.list1);
        links=new ArrayList<String>();
        names=new ArrayList<String>();
        try{

            URL url=new URL("http://api.androidhive.info/pizza/?format=xml");
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(false);
            XmlPullParser xpp = factory.newPullParser();
            xpp.setInput(getInputStream(url), "UTF_8");
            boolean insideItem = false;


                    // Returns the type of current event: START_TAG, END_TAG, etc..

            int eventType = xpp.getEventType();

            while (eventType != XmlPullParser.END_DOCUMENT) {

                    if (eventType == XmlPullParser.START_TAG) {


                        if (xpp.getName().equalsIgnoreCase("item")) {

                            insideItem = true;

                        } else if (xpp.getName().equalsIgnoreCase(UName)) {

                            if (insideItem)

                                names.add(xpp.nextText()); //extract the headline
                               // val=xpp.nextText();
                        } else if (xpp.getName().equalsIgnoreCase(UniUrl)) {

                            if (insideItem)

                                links.add(xpp.nextText()); //extract the link of article

                        }
                    }else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){

                        insideItem=false;

                    }

                    eventType = xpp.next(); //move to next element

                }


        }catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (XmlPullParserException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }catch (Exception e)
        {
            e.printStackTrace();

        }
        /*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);

                setListAdapter(adapter);*/
                 lv = getListView();
                   ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                            android.R.layout.simple_list_item_1, names);
                    setListAdapter(adapter); 



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

                               String bb=parent.getItemAtPosition(position).toString();
                               Intent i = new Intent(getApplicationContext(), Details.class);
                               //  String x=edt.getText().toString();
                                i.putExtra("name",bb);
                                // starting new activity
                                startActivity(i);

                        }
                    });
            }


    private InputStream getInputStream(URL url) {
        // TODO Auto-generated method stub
        try {
             return url.openConnection().getInputStream();
             } catch (IOException e) {
                   return null;
            }

    }

}


//detail activity:

    public class Details extends LastActivity{
        LastActivity last=new LastActivity();
        TextView tv;
        TextView url;
        String read;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.details);

            tv=(TextView) findViewById(R.id.text);
            //url=(TextView) findViewById(R.id.link);
            Intent intent=getIntent();

                // receiving  data
                String name = intent.getStringExtra("name");
               //String path=intent.getStringExtra("url");

                //Log.e("Second Screen", name + ".");
                //tv.setText(name);
               // url.setText(path);
        }
    }
  • 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-08T02:03:51+00:00Added an answer on June 8, 2026 at 2:03 am

    extend Activity instead of LastActivity in Details Activity

    public class Details extends Activity{
            //LastActivity last=new LastActivity();
           .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I receive data from web service my NSMutableData is filled with following XML:
I am trying to parse data from a xml web service but I am
I am using the following code to import my data from XML to mySQL.
At the moment i've got the following code to get data from an xml
Following code is written to fetch the data from the xml file. I think
I have the following Code to display Data from the Database in XML Document
The following code compares two XML texts and returns a collection of data changes
i inteded to show xml format on the console from following basic code :
I am trying to pass data from the database in XML format to an
I have the following data that I parsed from an xml file and now

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.