当前位置:首页 > 开发 > 编程语言 > XML > 正文

Xstream Cannot create XmlPullParser错误解决

发表于: 2013-10-29   作者:53873039oycg   来源:转载   浏览:
摘要:      昨天从官网上下了个Xstream,运行了一个简单的测试用例 public void testConvertsPropertiesObjectToShortKeyValueElements() { Properties in = new Properties(); in.setProperty("hello", &q

     昨天从官网上下了个Xstream,运行了一个简单的测试用例

public void testConvertsPropertiesObjectToShortKeyValueElements() {
		Properties in = new Properties();
		in.setProperty("hello", "world");
		in.setProperty("foo", "cheese");
		String expectedXML = "" + "<properties>\n"
				+ "  <property name=\"hello\" value=\"world\"/>\n"
				+ "  <property name=\"foo\" value=\"cheese\"/>\n"
				+ "</properties>";
		XStream xstream = new XStream();
		String actualXML = xstream.toXML(in);
		assertEquals(expectedXML, actualXML);

		Properties expectedOut = new Properties();
		expectedOut.setProperty("hello", "world");
		expectedOut.setProperty("foo", "cheese");
		Properties actualOut = (Properties) xstream.fromXML(actualXML);
		assertEquals(in, actualOut);
		assertEquals(in.toString(), actualOut.toString());
	}

    一运行,就报错了,错误信息如下:

   

com.thoughtworks.xstream.io.StreamException: Cannot create XmlPullParser
	at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:56)
	at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1011)
	at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1002)
	at com.xmljson.test.PropertiesConverterTest.testConvertsPropertiesObjectToShortKeyValueElements(PropertiesConverterTest.java:42)
	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)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:255)
	at junit.framework.TestSuite.run(TestSuite.java:250)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

   在初始化Xstream的地方看来下反编译的源码

  

public XStream()
    {
        this(null, (Mapper)null, ((HierarchicalStreamDriver) (new XppDriver())));
    }

    发现Xstream默认是使用XppDriver的

    把Xstream的Driver改为

   

XStream xstream = new XStream(new DomDriver());

    测试运行通过,至于为什么要使用DomDriver,还请各位大神指教,谢谢。

 

 

Xstream Cannot create XmlPullParser错误解决

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
今日,重装MySql 遇到一个错误,安装好运行MySQLServerInstanceConfigWizard,在最后一步却发现无法
环境:jdk1.6,glassfish,CXF2.7.6 在tomcat7测试是没有问题的,但是发布到glassfish就出现了。网
今日,重装MySql 遇到一个错误,安装好运行MySQLServerInstanceConfigWizard,在最后一步却发现无法
环境 MyEclipse 8.6 + SVN1.0.6 问题 SVN检出项目出现Cannot create project to checkout to错误 解
安装环境:Oracle 11g R2 X 64 + Navicat Premium(X64) 错误描述:安装完Navicat Premium后启动,连
  下午在使用Core Data进行数据持久化存储时,出现了Cannot create an NSPersistentStoreCoordina
转的: Cannot create PoolableConnectionFactory(Io 异常: The Network Adapter could not establi
Android library projects cannot be launched错误的解决方法: 右键工程根目录->properties 左
google之,网上给的解决方案是http://hi.baidu.com/zhangtianshun/item/9463abfcfd6045763d198b81
当运行eclipse时提示 NAND: could not create temp file for system NAND disk image: No such file
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号