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

  • Home
  • SEARCH
  • 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 9256073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:51:21+00:00 2026-06-18T11:51:21+00:00

I have this code which has to get a listview and populate it with

  • 0

I have this code which has to get a listview and populate it with an array adapter:

public class news extends ListActivity {
public String[] titoli = new String[99];
public String[] descrizioni = new String[99];

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new connection().execute();
    System.out.println("prova1");
}

public class connection extends AsyncTask<Void, Void, Void> {
    public Void doInBackground(Void... params) {
        System.out.println("prova2");
        // All static variables
        final String URL = "http://www.messedaglia.it/index.php/archivio-news?format=feed&type=rss";
        // XML node keys
        final String ITEM = "item"; // parent node
        final String TITLE = "title";
        final String DESC = "description";
        Element e = null;
        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(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>();
            e = (Element) nl.item(i);
            // adding each child node to HashMap key => value
            map.put(TITLE, parser.getValue(e, TITLE));
            map.put(DESC, parser.getValue(e, DESC));

            // adding HashList to ArrayList
            menuItems.add(map);
        }
        System.out.println("prova3");
        for (int c = 0; c < nl.getLength(); c++) {
            e = (Element) nl.item(c);
            titoli[c] = parser.getValue(e, TITLE); // name child value
            descrizioni[c] = parser.getValue(e, DESC);
        }
        return null;
    }

    public void onPostExecute() {
        System.out.println("prova4");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(news.this,
                android.R.layout.simple_list_item_1, titoli);
        System.out.println("prova5");
        ListView listView = (ListView) news.this
                .findViewById(android.R.id.list);
        listView.setAdapter(adapter);
    }
     }
 }

the log show a Null Pointer Exception here(line 33 of my code):

listView.setAdapter(adapter);

LOG:

02-07 13:38:36.020: E/AndroidRuntime(13803): FATAL EXCEPTION: main
02-07 13:38:36.020: E/AndroidRuntime(13803): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.messedagliavr.messeapp/com.messedagliavr.messeapp.news}: java.lang.NullPointerException
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.os.Looper.loop(Looper.java:137)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread.main(ActivityThread.java:4898)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at java.lang.reflect.Method.invoke(Method.java:511)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at dalvik.system.NativeStart.main(Native Method)
02-07 13:38:36.020: E/AndroidRuntime(13803): Caused by: java.lang.NullPointerException
02-07 13:38:36.020: E/AndroidRuntime(13803):    at com.messedagliavr.messeapp.news.onCreate(news.java:33)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.Activity.performCreate(Activity.java:5206)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
02-07 13:38:36.020: E/AndroidRuntime(13803):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
02-07 13:38:36.020: E/AndroidRuntime(13803):    ... 11 more
    

Most of you say to add setContentView(). I removed it because adding it I get this error:

error: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

  • 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-18T11:51:22+00:00Added an answer on June 18, 2026 at 11:51 am

    as in log :

    NullPointerException 02-07 13:38:36.020: E/AndroidRuntime(13803):
    at com.messedagliavr.messeapp.news.onCreate(news.java:33)

    because titoli array is empty. you are using AsyncTask for getting elements in titoli array then just move your adapter code onPostExecute method

    and use

    ListView listView = (ListView) findViewById(android.R.id.list);
    

    instead of

    ListView listView = (ListView) findViewById(R.id.list);
    

    to get ListView reference and must declare ListView id as android:id="@android:id/list" in xml layout if you are using

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

Sidebar

Related Questions

I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have this code (which is way simplified from the real code): public interface
I have this code which compiles and works as expected: class Right {}; class
My current application has one Activity, the main one which extends ListActivity (listview of
I have this code which adds a x number of views to a Multiview
I have this code which does the trick: #include <stdio.h> int main() { int
I have this code which is called at an onChange event of an function
I have this code which gets WP posts, but it gets all the posts
I have this code which will include template.php file from inside each of these
I have this code which should create a splash image with either no animation

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.