1. Are you ready for the Galaxy S20? Here is everything we know so far!

ListView Help: Resource Not Found

Discussion in 'Android Development' started by piper210, Apr 21, 2012.

  1. piper210

    piper210 Lurker
    Thread Starter

    Hi people.

    I am working on a project an am currently blocked. I created an arraylist with the info I want displayed in the listview. I used an array adapter and put that in the setListAdapter. All this is done by the book.

    However, when I run it, it goes through the whole program and then gives me an error that it can't find the list_item.xml resource. I check the path that it gave an it is there. I tried cleaning the project and restarting the computer but nothing works.

    Does anyone have any ideas as to how I can fix this? I'd really appreciate the help.

    Additional Info: I have been doing tests and it I learned that the program messes up when I use setListAdapter(value).

    fyi: The variable value is what i get from the array adapter.

    Hope this info is useful. I really need some help to solve this. I honestly don't know what to try next.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. piper210

    piper210 Lurker
    Thread Starter


    Code (Text):
    1. public class waFinalActivity extends ListActivity {
    2.     static ArrayList<String> stations=new ArrayList<String>();
    3.     /** Called when the activity is first created. */
    4.     @Override
    5.     public void onCreate(Bundle savedInstanceState) {
    6.         super.onCreate(savedInstanceState);
    7.         getAvailableStations();
    8.        
    9.        
    10.         ArrayAdapter<String> value=new ArrayAdapter<String>(this,R.layout.list_item,stations);
    11.         System.out.println("test1");
    12.         setListAdapter(value);
    13.         System.out.println("test2");
    14.         ListView lv=getListView();
    15.         lv.setAdapter(value);//<------------ gets stuck here
    16.         lv.setTextFilterEnabled(true);
    17.         System.out.println("test3: setting");
    18.     }
    19.    
    20.     /*protected void onListItemClick(ListView lv, View v,int position, long id){
    21.         super.onListItemClick(lv,v,position,id);
    22.         String openStation=stations.get(position);
    23.         try{
    24.             Cla
    25.         }
    26.         catch(){
    27.            
    28.         }
    29.     }*/
    30.    
    31.     /**********************************get station IDs***************************************/
    32.     private void getAvailableStations() {
    33.         AssetManager am=getAssets();
    34.         InputStream s = null;
    35.         try{
    36.             s=am.open("fl_wx_index.xml");
    37.             DocumentBuilderFactory dbFac=DocumentBuilderFactory.newInstance();
    38.             DocumentBuilder db=dbFac.newDocumentBuilder();
    39.             Document doc=db.parse(s);
    40.             doc.getDocumentElement().normalize();
    41.            
    42.             NodeList nL=doc.getElementsByTagName("station");
    43.  
    44.             for(int i=0;i<nL.getLength();i++){
    45.                 Node n=nL.item(i);
    46.                 if(n.getNodeType()==Node.ELEMENT_NODE){
    47.                     Element eElement=(Element)n;
    48.                     String value=getTagValue("station_id",eElement);
    49.                     stations.add(value);
    50.                 }
    51.             }
    52.             am.close();
    53.         }
    54.         catch(FileNotFoundException e){
    55.  
    56.         } catch (IOException e) {
    57.  
    58.             // TODO Auto-generated catch block
    59.             e.printStackTrace();
    60.         } catch (SAXException e) {
    61.             // TODO Auto-generated catch block
    62.             e.printStackTrace();
    63.         } catch (ParserConfigurationException e) {
    64.             // TODO Auto-generated catch block
    65.             e.printStackTrace();
    66.         }
    67.         finally{
    68.             try {
    69.                 s.close();
    70.             } catch (IOException e) {
    71.                 // TODO Auto-generated catch block
    72.                 e.printStackTrace();
    73.             }
    74.         }
    75.     }
    76.  
    77.     /*****************************************************************************************/
    78.     private String getTagValue(String sTag, Element eElement) {
    79.         NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
    80.         Node nValue = (Node) nlList.item(0);
    81.         return nValue.getNodeValue();
    82.     }
    83. }
     
  3. wubbzy

    wubbzy Well-Known Member

    where is your setcontentview() being called?
     
  4. piper210

    piper210 Lurker
    Thread Starter

    it extends listactivity so setContextView() doesn't have to be called.
    It shouldn't effect the result event if it is there, but I tried putting it and it gave me an error.
     
Loading...

Share This Page

Loading...