You need to sign in to do that
Don't have an account?
maybemedic
XmlStreamReader "Constructor not defined"
Hello All,
I am new to Apex development and I am going through the Apex reference document. I am trying to save a sample code in the doc, but it keeps giving me the Exception "Constructor Not defined". I am using the web interface on my DEV edition. It happens in Eclipse too. I'd appreciate if I get some help in this regard. Thanks.
I am new to Apex development and I am going through the Apex reference document. I am trying to save a sample code in the doc, but it keeps giving me the Exception "Constructor Not defined". I am using the web interface on my DEV edition. It happens in Eclipse too. I'd appreciate if I get some help in this regard. Thanks.
Code:
public class XmlStreamReader { // Create a class Book for processing public class Book { String name; String author; } Book[] parseBooks(XmlStreamReader reader) { Book[] books = new Book[0]; while(reader.hasNext()) { // Start at the beginning of the book and make sure that it is a book if (reader.getEventType() == XmlTag.START_ELEMENT) { if (reader.getLocalName()=='Book') { // Pass the book to the parseBook method (below) Book book = parseBook(reader); books.add(book); } } reader.next(); } return books; } // Parse through the XML, deterimine the auther and the characters Book parseBook(XmlStreamReader reader) { Book book = new Book(); book.author = reader.getAttributeValue('', 'author'); while(reader.hasNext()) { if (reader.getEventType() == XmlTag.END_ELEMENT) { break; } else if (reader.getEventType() == XmlTag.CHARACTERS) { book.name = reader.getText(); } reader.next(); } return book; } // Test that the XML string contains specific values static testMethod void testBookParser() { XmlStreamReader demo = new XmlStreamReader(); String str = '<books><book author="Manoj">Foo bar</book>' + '<book author="Mysti">Baz</book></books>'; XmlStreamReader reader = new XmlStreamReader(str); Book[] books = demo.parseBooks(reader); System.debug(books.size()); for (Book book : books) { System.debug(book); } } }
If you change it to something like XMLRead, it should work:
All Answers
If you change it to something like XMLRead, it should work:
Thanks so much. I should have known that. :smileyhappy: