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]
# 1
did you install kxml or create an XmlParser class?
suparenoa at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
I am sorry, I actually don't know how to create XmlParser class..well I had installed kxml2.0.
Momia at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
did you import XmlParser ?did you import kxml in your project classpath?
suparenoa at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
yup,here they are...import org.kxml2.io.*;import org.xmlpull.v1.*;want an immediate reply....
Momia at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

> want an immediate reply....

you want an immediate reply? i hope you are joking...

so, when you create your package (with eclipseme for example), did you export additional

jar with your MIDlet suite created? the export function adds the external jar to the application

jar

suparenoa at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 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 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
> anyways,i didnt create any package..Do i still need to add external jar?you should add the jar needed to use XmlPullParse...
suparenoa at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

>you should add the jar needed to use XmlPullParse...

is that xmlpull_1_1_3_4c_all.zip ?

< contains everything needed to regenerate XMLPULL V1 API distribution including all source files, documentation, build scripts, precompiled .class files and JAR files, and required ANT and JUnit .jar files>

if yes, where to save this folder?

Momia at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
you just to include the jar in your build path . i don't know if you use an IDE (eclipse andeclipseme is good)check out this documentation http://java.sun.com/j2me/docs/wtk2.2/docs/UserGuide-html/projects.html#wp47758
suparenoa at 2007-7-12 21:51:03 > top of Java-index,Java Mobility Forums,Java ME Technologies...