Results 1 to 9 of 9
  1. #1
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Parsing xml attributes crash

    Hi

    Im quite n00bis about java programming. Looking through a lot of tutorials on how to pars xml.

    Here is a cut of the xml I want to parse
    Java Code:
    <Component>
      <Type Name="1">
        <Item ItemNo="1"		Name="First" Value="1" Config="1"></Item>
      </Type>
    
      <Type Name="2">
        <Item ItemNo="2"	        Name="1" Value="3"  Config="2"></Item>
        <Item ItemNo="3"     	Name="3" Value="" Config="3"></Item>
      </Type>
    </Component>

    I have found a great tutorial here: simple sax xml parser

    But when the xml comes to the last "node end" ( </Component>) I get this error:

    Java Code:
    at org.eclipse.swt.SWT.error(SWT.java:4263)
    	at org.eclipse.swt.SWT.error(SWT.java:4197)
    	at org.eclipse.swt.SWT.error(SWT.java:4168)
    	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
    	at org.eclipse.swt.widgets.TableItem.setText(TableItem.java:1162)
    	at view.Main.openXML(Main.java:214)
    	at view.Main$2.widgetSelected(Main.java:96)
    	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
    	at view.Main.open(Main.java:61)
    	at view.Main.main(Main.java:46)
    and my application closes.

    Can anyone help me??

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,024
    Blog Entries
    7
    Rep Power
    20

    Default Re: Parsing xml attributes crash

    I deleted you other identical thread; both threads were moderated and I approved this one so it's visible to everyone now.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,024
    Blog Entries
    7
    Rep Power
    20

    Default Re: Parsing xml attributes crash

    According to the stack trace I don't think the error has something to do with parsing the XML text; a SWT widfget complains; I think it's an error in your gui.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Parsing xml attributes crash

    Well the thing is that I tried to put a string array (that was empty) into a table.

    The next thing for me is to figure out how to turn the console output into a string, pref a string array.

    From the tutorial I have this code bit:
    Java Code:
    private static final class SaxHandler extends DefaultHandler {
    	        // invoked when document-parsing is started:
    		  
    		  StringBuffer accumulator = new StringBuffer(); // Accumulate parsed text
    
    	        public void startDocument() throws SAXException {
    	            System.out.println("Document processing started");
    	        }
    	        
    	        // notifies about finish of parsing:
    	        public void endDocument() throws SAXException {
    	            System.out.println("Document processing finished");
    	        }
            public void startElement(String uri, String localName, 
                    String qName, Attributes attrs) throws SAXException {
            	 accumulator.setLength(0);
                if (qName.equals("Component")) {
                } else if (qName.equals("Type")) {
                	 
                	String TypeName = attrs.getValue("Name");
                	System.out.println("Type "+ TypeName);
                	
                } else if (qName.equals("Item")) {
                	
    //            	 ItemNo value as String:
                  String ItemNo = attrs.getValue("ItemNo");
                  // name as a String:
                  String Name = attrs.getValue("Name");
                  // value as a String:
                  String Value = attrs.getValue("Value");
                  // config value as a String:
                  String Config = attrs.getValue("Config");
                 
                  String XMLtable = ItemNo + Name + Value + Config;
                  System.out.println("Item " + ItemNo +" " + Name +" " + Value +" "+ Config);
                  
                  
                            }  else {
                            	
                    throw new IllegalArgumentException("Element '" + 
                            qName + "' is not allowed here");
                            }
                
                
            }
            
            // we leave element 'qName' without any actions:
            public void endElement(String uri, String localName, String qName)
            throws SAXException {
                // do nothing;
            }
           
           }
    I cannot get access to the XMLtable string array.

    EDIT:
    I would also like to have all TypeName strings in a array (or similar) so i can have them i a Combo

    Any ide?

    Thanks for answering so fast anyways
    Last edited by KarlNorway; 12-19-2011 at 12:30 PM. Reason: Adding stuff

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Parsing xml attributes crash

    What is the actual exception.
    I can only see the stack trace.

  7. #7
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Parsing xml attributes crash

    I forgot to add it in I'm sorry here it is..

    Java Code:
    java.lang.IllegalArgumentException: Argument cannot be null
    these lines caused the exception:


    Java Code:
    TableItem item1 = new TableItem(table, SWT.NONE);
    	    item1.setText(XMLItem);
    the String array XMLItem is empty..

    But as I asked. Is there a way of getting the
    Java Code:
    system.out.println
    converted to a string or string array?

  8. #8
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: Parsing xml attributes crash

    You are using qualified names instead of local names, so I take it that you do not have any default namespace declarations in your XML document?

    EDIT: Actually, qname and localname should be the same in your case...

    You haven't shown us the declaration for XMLItem so how can we help?
    Last edited by 2by4; 12-19-2011 at 04:21 PM.

  9. #9
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Parsed xml strings to string array

    The XMLItem is decleared in the top of the "main" class this way
    Java Code:
    Public String [] XMLItem;
    The thing is that I want the strings created in the parsed section to become a string array that i can put in my Table as in the picture.
    I get all the stuff from the XML into the console view of eclipse. But cant quite figure out how to put it into a string array so that I can put it in the table.

    I dont have the code in front of me right now but I know this is how ;)

    I dont use it anywhere else than right here..


    Maybe this should go into another thread??
    Attached Thumbnails Attached Thumbnails Parsing xml attributes crash-new-picture.bmp  
    Last edited by KarlNorway; 12-20-2011 at 08:43 AM. Reason: Changing topic

Similar Threads

  1. A JVM Crash.
    By mbb in forum New To Java
    Replies: 0
    Last Post: 06-10-2011, 11:25 AM
  2. Parsing XML attributes
    By javanewbie2020 in forum XML
    Replies: 1
    Last Post: 11-02-2010, 12:39 PM
  3. JVM crash
    By darsh in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 10-15-2010, 09:55 AM
  4. AWT JVM Crash
    By Java_Zak in forum AWT / Swing
    Replies: 0
    Last Post: 07-29-2010, 10:13 AM
  5. JVM crash in Linux
    By ragav123 in forum Advanced Java
    Replies: 10
    Last Post: 05-22-2010, 06:16 AM

Posting Permissions

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