Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to replace the items in an AWT List

    I have a project at the minute which is basically a medical conditions and symptoms database. Basically the idea is that the user can select a symptom from one List which will then update another list with all the related condition. Then the user can select a condition from that list and view information on it.

    The problem occurs when I try to update the conditions list after a symptom has been selected. The action event works fine but I just can't make it update the conditions list. Here is the method that's supposed to do that

    Code:
    private void getConditions(String selected)
    {
    	db.result = db.selectQuery(query);
    	String[] conditionList = db.stringArray(db.result, "conditionName");
    		
    	conditions = new List(10);
    	for(int i = 0; i < conditionList.length; i++)
    	{
    		conditions.add(conditionList[i]);
    	}
    }
    I tried using conditions.removeAll() to empty the list but it always produced a run-time error so I decided to try making a new List but no luck. The list is inside a JPanel.

    Anyone got any ideas on how to solve this?

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by jmitch18 View Post
    I tried using conditions.removeAll() to empty the list but it always produced a run-time error
    what was the error?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at SymptomSelect.getConditions(SymptomSelect.java:47)
    	at SymptomSelect.actionPerformed(SymptomSelect.java:34)
    	at java.awt.List.processActionEvent(Unknown Source)
    	at java.awt.List.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    are u sure db is not null and db.stringArray does not return a null?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah I just made a loop to print each index of conditionsList to the console and they appeared alright.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •