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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:48+00:00 2026-05-23T14:59:48+00:00

I have an odd problem, (see shorter version at the bottom first please) When

  • 0

I have an odd problem, (see shorter version at the bottom first please)

When my activity starts for the first time, the listview shows the dataset fine. The adapter is a custom adapter which shows 2 rows of text and an image. I call an asynctask upon a click event to the listview, the dataset updates in accordance with whatever was clicked on in the listview – more specifically the arrays which are associated with the adapter become rewritten with the parsings of some xml, and then notifyachapterdatasetchanged method is called to update the listview in the onPostExecute function. However I always get NullPointerException when I am iterating through some xml (which is very well formed and validates). ALso its worth mentioing that the algorithm that parses the desired values is good, because as mentioned above, if i write to just 1 element of the array then I dont get the error I just get the last node value so its looping in the correct places. i.e If I simple try to copy the current node value I am parsing during the loop into, say, producyTypes[0] then the last value from within the loop actually makes it to the listview as it constantly overwrites this elemet of the array

Here is my code.`

public class main extends Activity implements OnItemClickListener

{

String selectedType="";
ListView lview3;
ImageView iv;
ListViewCustomAdapter adapter;
String test = "";
List<String> ls;

String productTypes[] = {"Monitor","Components","Systems","Laptops","Flash / Usb Memory",
        "Networking","Cables","Peripherals","Sound and Vision", "Software"};

String productsIncluded[] = {"Sizes (inches) 17, 19, 20",
        "Motherboards, PSU, Cases, Fans/Heatsinks/Coolers, Barebones Systems, Blue-Ray/DVD. Card Readers, Controller Cards, Drive Enclosures, Sound Cards",
        "Bundles, Switches and Hubs, Print Servers, Accessories/Modules",
        "Cables for: Drives, Networking, HDMI/Monitor, Audio/Video, USB/Firewire, Power, Miscellaneous",
        "Mice, Connectors, Bluetooth Devices",
        "Mp3/Mp4  Solar Panel",
        "Anti-Virus, Internet Security, Operating Systems, Office,,
        "",
        ""};

private static int images[] = {R.drawable.monitor, R.drawable.components, R.drawable.systems, 
    R.drawable.laptops, R.drawable.flashusb, R.drawable.networking, R.drawable.cables, R.drawable.
    peripherals, R.drawable.soundandvision, R.drawable.software};

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


    iv = (ImageView)findViewById(R.id.ImageView01);
    iv.setImageResource(R.drawable.logo);
    iv.setVisibility(View.VISIBLE);
    lview3 = (ListView) findViewById(R.id.listView3);
    adapter = new ListViewCustomAdapter(main.this, productTypes, productsIncluded, images);
    lview3.setAdapter(adapter);
    lview3.setOnItemClickListener(main.this);

}

@Override
public void onItemClick(AdapterView arg0, View arg1, int position, long id) {

     selectedType = "";                    

    if(position == 0)
    {
        selectedType= "Monitors";           
    }
    if(position == 1)
    {
        selectedType= "Hard Drives";            
    }
       Toast.makeText(this, Integer.toString(position), Toast.LENGTH_SHORT).show();      
       new async().execute();

    /*
    Intent intent = new Intent(getApplicationContext(),activitywo.class);
    Bundle bundle =new Bundle(); 
    bundle.putString("selectedType",selectedType);       
    intent.putExtras(bundle);              
    startActivity(intent);
    //Toast.makeText(this, "Title => "+productTypes[position]+" \n Description => "+productsIncluded[position], Toast.LENGTH_SHORT).show();      
    */
}
 private class async extends AsyncTask<String, Void, Void> {

     // UI Thread
     protected void onPreExecute() {

     }

     // automatically done on worker thread (separate from UI thread)
     protected Void doInBackground(final String... args) {

         try{

             Resources res = getResources();
             InputStream in;
             in = res.openRawResource(R.raw.core);

             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             DocumentBuilder builder = factory.newDocumentBuilder();
             Document dom = builder.parse(in);
             Element root = dom.getDocumentElement();
             NodeList items = root.getElementsByTagName("entry");


            count=0;
            for(int i =0;i<items.getLength();i++){
                Node item = items.item(i); 
                NodeList properties = item.getChildNodes();
                //productsDefinedByTypeArray = new String[properties.getLength()];


                for(int j = 0;j<properties.getLength();j++){
                    Node property = properties.item(j);
                    String name = property.getNodeName();

                    if(name.equalsIgnoreCase("g:product_type")){//everytime we hit g:product_type grab the value
                        String strText = property.getFirstChild().getNodeValue();

                        if(strText.contains(selectedType)){
                  //        
                            for(int k = 0;k<properties.getLength();k++){
                                Node propertysecond = properties.item(k);
                                String namesecond = propertysecond.getNodeName();
                                if(namesecond.equalsIgnoreCase("title")){//everytime we hit title grab the value
                                    String strTextsecond = propertysecond.getFirstChild().getNodeValue();
                                    productTypes[0] = strTextsecond;

                                    yo = strTextsecond;
                                    count++;
                                }                                    
                            }                                
                        }
                    }

                }


            }

The code crashes at the point where I am trying to copy the value of a “title” node that I parse out of my xml file into the list-String-. I am using a list-string- to show that even if you try and copy the value into the array itself (the array that is associated with the adapter), even if you comment out the notifydatasetchanged () line the program still crashes. The xml is well formed and very consistent. I know this because (aecept the fact its really small and I have read it all) ! Why can I not copy every node value into my array/list whilst the loop is in progress?

Any help is massively appreciated. Thank you.

Shorter version:

I cannot write to the List

 if(strText.contains(selectedType)){
                   //        
                             for(int k = 0;k<properties.getLength();k++){
                                 property = properties.item(k);
                                 name = property.getNodeName();
                                 if(name.equalsIgnoreCase("title")){//everytime we hit title grab the value
                                     String strTextsecond = property.getFirstChild().getNodeValue().toString();


                                     ls.add(strTextsecond.toString());

                                     //test = strTextsecond;

                                 }   

                             }         

                         }
  • 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-05-23T14:59:48+00:00Added an answer on May 23, 2026 at 2:59 pm

    Maybe you forget initialize ls? I don’t find in your code something like:

    ls = new List<String>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note, I have found the solution to my problem. Please see below. I'm converting
I have an odd problem...I'm using a documentation generator which generates a lot of
I have an odd problem in VS2008 running unit tests. When I run the
I have the odd problem that I am not able to open the properties
I have an odd problem with Django. I have a set of objects that
I have an odd problem where Hibernate is running more queries than I've asked
I recently encountered an odd problem with RSACryptoServiceProvider.VerifyHash . I have a web application
I am having a really odd problem with Flash CS4. I have a MovieClip
I have an odd problem in silverlight. I use the following XAML to bind
I have an extremely odd problem in my JUnit tests that I just can't

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.