1

运行 JUnit 测试时

 /**
 * Test
 */
public void testParser()
{
    Route route = new Route("Tom's Creek", "TC");
    Stop stop = new Stop("Progress/Broce Nbnd", "1305");
    List<String> result = null;
    try {
        result = parser.getTimesForRouteAndStop(route, stop);
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    for (int i = 0; i < result.size(); i++)
    {
        System.out.println(result.get(i));
    }
    assertNotNull(result);
}

我收到错误:

    java.lang.NoClassDefFoundError: android/util/Xml
at com.cs2114.vttransit.Parser.getTimesForRouteAndStop(Parser.java:54)
at com.cs2114.vttransit.ParserTest.testParser(ParserTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
...

我正在测试的解析器类方法:

    public List<String> getTimesForRouteAndStop(Route route, Stop stop)
        throws XmlPullParserException, IOException {
    String url = "http://www.bt4u.org/webservices/BT4U_WebService.asmx/GetNextDepartures?routeShortName="
            + route.getShortName() + "&stopCode=" + stop.getStopCode();
    InputStream in = downloadUrl(url);
    try {
        XmlPullParser parser = android.util.Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        return readNextDepartures(parser);
    } finally {
        in.close();
    }
}

调用 android.util.Xml.newPullParser() 的行正在产生错误。

有一段时间了,我知道这与android jar有关,但我不知道是什么。

4

0 回答 0