2011-04-19 66 views
0

我幾個星期前寫了一個可用的XML-Saxparser。出於某種原因,我不知道爲什麼,它不再工作了,我想不出我在這些課上做了什麼。 當我查看調試器時,最後一件工作是URL url = new URL("http://hammerman.bplaced.net/Objekteingabe1.xml");SAX-Parser拋出UnknownHostException

xr.parse(new InputSource(url.openStream()));似乎拋出IOException。 catch子句中的「e」的詳細信息顯示爲「UnknownHostException」或「Host is unolved」:...「stackTrace:null。

正如我所說,我真的不知道發生了什麼,所以我認爲我做了一個愚蠢的misstake某處或刪除了一行。但我現在搜索了幾個小時,我找不到它。 希望有人能幫助我。

非常感謝。 費邊

我Readerhelper看起來如下

try { 
     SAXParserFactory spf = SAXParserFactory.newInstance(); 
     sp = spf.newSAXParser(); 
     XMLReader xr = sp.getXMLReader(); 
     handler = new Dokukmentenhandler(); 
     xr.setContentHandler(handler); 
     URL url = new URL("http://hammerman.bplaced.net/Objekteingabe1.xml"); 

     xr.parse(new InputSource(url.openStream())); 
//  Textobjekte = handler.Textobjekte; 
// Phasen_anzahl = handler.Phasen_Counter; 

    } catch (ParserConfigurationException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (SAXException e) { 
     // TODO Auto-generated catch block 

     e.printStackTrace(); 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 

     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 

     e.printStackTrace(); 
    } 

和我的處理程序

@Override 
    public void startDocument() throws SAXException 
    { 

    } 

    @Override 
    public void startElement(String namespaceURI, String localName, String tagName, Attributes attributes) throws SAXException 
    { 
     // lege ein erstes dData objekt an 
     if (localName.equals("tData")) { 
     aktuell = new Textobjekt(); 
     // damit das objekt existiert 
     currentVal = ""; 
    } 
     // alle 4 Sensorarten werden abgefangen 
     if (localName.equals("Realer_Sensor")) { 
      realerSensor = true; 
      op = new Option(); 
     }else if (localName.equals("Normalverteilung")) { 
      normalverteilung = true; 
      op = new Option(); 
      op.Sensor_name= "Normalverteilung"; 
     }else if (localName.equals("Bernoulliverteilung")) { 
      bernoulli = true; 
      op = new Option(); 
      op.Sensor_name= "Bernoulliverteilung"; 
     }else if (localName.equals("Gleichverteilung")) { 
      gleichverteilung = true; 
      op = new Option(); 
      op.Sensor_name= "Gleichverteilung"; 
     } 
    } 
    @Override 
    public void endElement(String namespaceURI, String localName, String tagName) throws SAXException 
    { 
     if (localName.equals("Variablen_Name")) { 
     aktuell = new Textobjekt(); 
     aktuell.Variablenname = currentVal; 
     Textobjekte.add(aktuell); 
    }else if (localName.equals("Phasenanzahl")) { 
     Phasen_Counter = Integer.parseInt(currentVal); 

    }else if (localName.equals("Initialwert")) { 
     aktuell.Initialwert = Float.parseFloat(currentVal); 
    } 
    // alle 4 Sensorarten werden abgefangen, die booleans geschlossen und die optionen hinzugefuegt 
    else if (localName.equals("Realer_Sensor")) { 
     realerSensor = false; 
     aktuell.Optionenliste.add(op); 
    }else if (localName.equals("Normalverteilung")) { 
     normalverteilung = false; 
     aktuell.Optionenliste.add(op); 
    }else if (localName.equals("Bernoulliverteilung")) { 
     bernoulli = false; 
     aktuell.Optionenliste.add(op); 
    }else if (localName.equals("Gleichverteilung")) { 
     gleichverteilung = false; 
     aktuell.Optionenliste.add(op); 
    } 
    else if (localName.equals("Sensor_Name")) { 

      op.Sensor_name = currentVal; 

    } 
    else if (localName.equals("Parameter")) { 
     if (realerSensor) { 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 

    }else if (localName.equals("Nu")) { 
     if (normalverteilung) { 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 

    }else if (localName.equals("sigma")) { 
     if (normalverteilung) { 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 
    } 
    else if (localName.equals("Pi")) { 
     if(bernoulli){ 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 
    } 
    else if (localName.equals("Untere_Wertegrenze")) { 
     if (gleichverteilung) { 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 
    } 
    else if (localName.equals("Obere_Wertegrenze")) { 
     if (gleichverteilung) { 
      float f = Float.parseFloat(currentVal); 
      op.list.add(f); 
     } 
    } 
    // Ende der Optionenliste 


    else if (localName.equals("Eventvorkommen")) { 
     aktuell.Eventvorkommen = currentVal; 
    } 
    else if (localName.equals("Bezugsart")) { 
     aktuell.Bezugsart = currentVal; 
    } 
    else if (localName.equals("Eventart")) { 
     aktuell.Eventart = currentVal; 
    } 
    else if (localName.equals("Ueberschreitungswert")) { 
     float f = Float.parseFloat(currentVal); 
     aktuell.Ueberschreitungswert = f; 
    } 
    else if (localName.equals("Auswirkung")) { 
     float f = Float.parseFloat(currentVal); 
     aktuell.Auswirkung = f; 
    } 
    else if (localName.equals("Objektname")) { 
     re = new Referenz(); 
     re.Objektname = currentVal; 
    } 
    else if (localName.equals("Referenzwert")) { 
     float f = Float.parseFloat(currentVal); 
     re.Referenzwert = f; 
     aktuell.referenzliste.add(re); 
    } 


    } 

    @Override 
    public void characters(char[] ch, int start, int length) 
    throws SAXException { 
     if (length > 0) { 
     currentVal = new String(ch,start,length); 
    } 
    } 
} 

回答

0

這聽起來很像http://hammerman.bplaced.net/Objekteingabe1.xml無法達成。你能從瀏覽器撥打這個地址嗎?

如果是這樣,第二個選項可以是解析器看到

<Rahmeneingabe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="Objekteingabe.xsd"> 

,並嘗試加載XSD和失敗。

通常情況下,您應該獲取堆棧跟蹤中無法解析的主機的名稱。

+0

你是對的......由於一些愚蠢的原因,我刪除了我的項目中的xsd文件。刪除「xsi:noNamespaceSchemaLocation =」Objekteingabe.xsd「解決了我的問題!驗證並不重要!非常感謝Heiko! – fabian 2011-04-19 22:48:54

0

除非我在輸入時進行了更改,否則引用的URL & XSD文件是正確的,所以不是問題(我可以在我的瀏覽器中加載它們)。

這很可能是測試設備上的網絡連接問題,因爲它無法解析主機的名稱。

0

校正由法比安:

它似乎像菲爾斯的答案是正確的,它的工作時,我沒有像以前提到的(太?)(刪除的xsi:noNamespaceSchemaLocation =「Objekteingabe.xsd),但可能會被意外發生了。 大家誰都有同樣的問題:改變測試設備是一個不錯的選擇

我剛剛得到了同樣的問題又來了,並開始另一個仿真解決我的問題 遺憾的混亂,這裏!!!

1

記住清單中的互聯網用戶權限..

uses-permission android:name="android.permission.INTERNET"