Where to locate Class XmlParser?
Hi,
I compiled sample code from this site and I got error while building it....can anybody quickly point the solution?
I am using WTK 2.0...This is the output ...
C:\WTK22\apps\Sun\src\RSSParser.java:40: cannot find symbol
symbol : class XmlParser
location: class RSSParser
XmlParser parser = new XmlParser(reader);
^
C:\WTK22\apps\Sun\src\RSSParser.java:40: cannot find symbol
symbol : class XmlParser
location: class RSSParser
XmlParser parser = new XmlParser(reader);
^
C:\WTK22\apps\Sun\src\RSSParser.java:41: cannot find symbol
symbol : class ParseEvent
location: class RSSParser
ParseEvent pe = null;
^
C:\WTK22\apps\Sun\src\RSSParser.java:44: cannot find symbol
symbol : variable Xml
location: class RSSParser
parser.read(Xml.START_TAG, null, "rss");
^
C:\WTK22\apps\Sun\src\RSSParser.java:46: cannot find symbol
symbol : variable Xml
location: class RSSParser
parser.read(Xml.START_TAG, null, "channel");
^
C:\WTK22\apps\Sun\src\RSSParser.java:52: cannot find symbol
symbol : variable Xml
location: class RSSParser
if (pe.getType() == Xml.START_TAG) {
^
C:\WTK22\apps\Sun\src\RSSParser.java:57: cannot find symbol
symbol : variable Xml
location: class RSSParser
while ((pe.getType() != Xml.END_TAG) ||
^
C:\WTK22\apps\Sun\src\RSSParser.java:60: cannot find symbol
symbol : variable Xml
location: class RSSParser
if (pe.getType() == Xml.START_TAG &&
^
C:\WTK22\apps\Sun\src\RSSParser.java:65: cannot find symbol
symbol : variable Xml
location: class RSSParser
else if (pe.getType() == Xml.START_TAG &&
^
C:\WTK22\apps\Sun\src\RSSParser.java:70: cannot find symbol
symbol : variable Xml
location: class RSSParser
else if (pe.getType() == Xml.START_TAG &&
^
C:\WTK22\apps\Sun\src\RSSParser.java:79: cannot find symbol
symbol : variable Xml
location: class RSSParser
while ((pe.getType() != Xml.END_TAG) ||
^
C:\WTK22\apps\Sun\src\RSSParser.java:84: cannot find symbol
symbol : variable Xml
location: class RSSParser
if (pe.getType() == Xml.END_TAG &&
^
12 errors
com.sun.kvem.ktools.ExecutionException
Build failed
regards,
Momi
[2483 byte] By [
Momia] at [2007-11-27 9:10:04]

# 6
thanks Supareno!!
anyways,i didnt create any package..Do i still need to add external jar?
here is the output:
C:\WTK22\apps\XMLTEST\src\XMLTest.java:79: newPullParser() in org.xmlpull.v1.XmlPullParserFactory cannot be applied to (java.io.InputStreamReader)
XmlPullParser xpp =factory.newPullParser(in);
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:101: cannot find symbol
symbol : class ParseEvent
location: class XMLTest
ParseEvent event = xpp.read();
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:101: cannot find symbol
symbol : method read()
location: interface org.xmlpull.v1.XmlPullParser
ParseEvent event = xpp.read();
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:103: cannot find symbol
symbol : variable Xml
location: class XMLTest
case Xml.START_TAG:
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:108: cannot find symbol
symbol : variable Xml
location: class XMLTest
case Xml.END_TAG:
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:113: cannot find symbol
symbol : variable Xml
location: class XMLTest
case Xml.TEXT:
^
C:\WTK22\apps\XMLTEST\src\XMLTest.java:118: cannot find symbol
symbol : variable Xml
location: class XMLTest
case Xml.END_DOCUMENT:
^
7 errors
com.sun.kvem.ktools.ExecutionException
Build failed
Code:
import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import org.kxml2.io.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
* Simple MIDlet that demonstrates how an XML document can be
* parsed using kXML or NanoXML.
*/
public class XMLTest extends MIDlet {
// Our XML document -- normally this would be something you
// download.
private static String xmlDocument =
"<list><item>apple</item>" +
"<item>orange</item>" +
"<item>pear</item></list>";
private Display display;
private Command exitCommand = new Command( "Exit",
Command.EXIT, 1 );
public XMLTest(){
}
protected void destroyApp( boolean unconditional )
throws MIDletStateChangeException {
exitMIDlet();
}
protected void pauseApp(){
}
protected void startApp() throws MIDletStateChangeException {
if( display == null ){ // first time called...
initMIDlet();
}
}
private void initMIDlet(){
display = Display.getDisplay( this );
String [] items;
items = parse( xmlDocument );
display.setCurrent( new ItemList( items ) );
}
public void exitMIDlet(){
notifyDestroyed();
}
// Parses a document using kXML, looking for "item"
// nodes and returning their content as an
// array of strings.
private String[] parse( String xml ){
try {
ByteArrayInputStream bin =
new ByteArrayInputStream( xml.getBytes() );
InputStreamReader in = new InputStreamReader( bin );
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
factory.setNamespaceAware(true);
XmlPullParser xpp =factory.newPullParser(in);
//XmlParser parser = new XmlParser( in );
Vector items = new Vector();
parseItems( xpp, items );
String[] tmp = new String[ items.size() ];
items.copyInto( tmp );
return tmp;
}
catch( IOException e ){
return new String[]{ e.toString() };
}
}
private void parseItems( XmlPullParser xpp, Vector items )
throws IOException {
boolean inItem = false;
while( true ){
ParseEvent event = xpp.read();
switch( event.getEventType() ){
case Xml.START_TAG:
if( event.getName().equals( "item" ) ){
inItem = true;
}
break;
case Xml.END_TAG:
if( event.getName().equals( "item" ) ){
inItem = false;
}
break;
case Xml.TEXT:
if( inItem ){
items.addElement( event.getText() );
}
break;
case Xml.END_DOCUMENT:
return;
}
}
}
// Simple List UI component for displaying the list of
// items parsed from the XML document.
class ItemList extends List implements CommandListener {
ItemList( String[] list ){
super( "Items", IMPLICIT, list, null );
addCommand( exitCommand );
setCommandListener( this );
}
public void commandAction( Command c, Displayable d ){
if( c == exitCommand ){
exitMIDlet();
}
}
}
}
Momia at 2007-7-12 21:51:03 >
