PDA

View Full Version : [JAVA] Problemi nel main


F@lkland§
28-06-2008, 13:55
Ciao ragazzi!
Allora mi serve una classe che mi legga un file XML, ho scritto questo ma ho un errore nel main, perņ non riesco a capire cosa c'č che non va, posto il codice.
Spero riusciate ad aiutarmi.


import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;


public class LeggereXml extends DefaultHandler
{
static public String file="foo.xml";
static public String nodo;
public static void main(String args[])
{
DefaultHandler handler = new LeggereXml();
SAXParserFactory factory = SAXParserFactory.newInstance();
try
{
out = new OutputStreamWriter(System.out, "UTF8");
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(file, handler);
}
catch (Throwable t) { t.printStackTrace(); }
}

static private Writer out;

public void startElement(String namespaceURI,String lName,String
qName,Attributes attrs)throws SAXException{
String name = lName;
if ("".equals(name)) {nodo=qName;}
}

public void endElement(String namespaceURI,String sName,String qName) throws
SAXException{
String name = sName;
if ("".equals(name)) {nodo=qName;}
}

public void characters(char buf[], int offset, int len) throws SAXException{
String s = new String(buf, offset, len);
if(s.length()>1){
if(nodo=="autore") System.out.println(nodo+"-> "+s);
if(nodo=="titolo") System.out.println(nodo+"-> "+s);
if(nodo=="costo") System.out.println(nodo+"-> "+s);
}
}
}

wizard_at
28-06-2008, 14:39
metti il codice tra [ C0DE ] atrimenti e' pressoche' illeggibile

vladix
28-06-2008, 15:15
io ho eseguito il tuo codice e nn mi da nessun errore ... scommetto che e un FileNotFoundException ...

wizard_at
28-06-2008, 15:34
io ho eseguito il tuo codice e nn mi da nessun errore ... scommetto che e un FileNotFoundException ...

in effetti potrebbe essere...che errori ti da?

vladix
28-06-2008, 15:55
in effetti potrebbe essere...che errori ti da?

nn ho detto che mi da errore ... ma xche nn ci posti il stack trace del errore ...

F@lkland§
28-06-2008, 17:38
mi dice:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at xml.LeggereXml.main(LeggereXml.java:11)

F@lkland§
28-06-2008, 17:45
il file foo.xml č un semplice file....il tutto mi serve per leggere un file xml...


<?xml version="1.0" ?>
- <libri>
- <libro>
<autore>pippo</autore>
<titolo>primo titolo</titolo>
<costo>11</costo>
</libro>
- <libro>
<autore>sandro</autore>
<titolo>secondo titolo</titolo>
<costo>34</costo>
</libro>
</libri>

vladix
30-06-2008, 09:38
decisamente non e il file xml il problema ... io ho cercato un po su google (http://www.google.it/search?q=java.lang.Error%3A+Unresolved+compilation+problem&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:it:official&client=firefox-a) ma non sono riuscito a capire quale potrebbe essere il problema ... ( anche xche a me non da errore ) ,

wizard_at
30-06-2008, 09:42
come lo compili?