1

I'm pretty new to Java. I have an XML file which I managed to create from an ArrayList using xStream.toXML.

My Client class has the following objects:

  • String: name, id

  • Integer: balance

  • ArrayList: phone

  • ArraList: bestDay

  • Item (custom class): Data

My Item class has the following objects:

  • String: name

  • Integer: price

The XML file looks like this:

<list>
  <client>
    <name>Client 1</name>
    <id>054.658.547-74</id>
    <phone>
      <string>99564-5412</string>
      <string>7854-5478</string>
    </phone>
    <bestDay>
      <int>10</int>
    </bestDay>
    <balance>-20.0</balance>
    <data>
      <item>
        <name>Item 1</name>
        <price>5.0</price>
      </item>
      <item>
        <name>Item 2</name>
        <price>3.0</price>
      </item>
      <item reference="../item"/>
      <item reference="../item[2]"/>
    </data>
  </client>
  <client>
    <name>Client 2</nome>
    <id>047.654.987-78</id>
    <phone>
      <string>99564-1475</string>
      <string>98544-5254</string>
    </phone>
    <bestDay>
      <int>15</int>
      <int>30</int>
    </bestDay>
    <balance>-15.0</balance>
    <data>
      <item>
        <name>Item 3</name>
        <price>4.0</price>
      </item>
      <item reference="../item"/>
      <item reference="../item"/>
      <item reference="../item"/>
      <item reference="../item"/>
    </data>
  </client>
</list>

Now, when I try to make this code into an ArrayList again, using this code:

XStream xStream = new XStream();
String rawXML = new String(Files.readAllBytes(Paths.get("output.xml")));
ArrayList<Client> = (ArrayList<Client>)xStream.fromXML(rawXML);

I get an error at the last line.

EDIT:

Ok, I had only added to the buildpath:

  • xstream-1.4.10.jar

  • xpp3_min-1.1.4c.jar

Now I added xmlpull-1.1.3.1.jar and I have another error:

Security framework of XStream not initialized, XStream is probably vulnerable.
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message       : cliente
class               : java.util.ArrayList
required-type       : java.util.ArrayList
converter-type      : com.thoughtworks.xstream.converters.collections.CollectionConverter
path                : /list/cliente
line number         : 2
version             : 1.4.10
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1486)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1466)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1337)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1328)
    at application.Cliente.load(Cliente.java:88)
    at application.Main.main(Main.java:40)
    ... 11 more
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: cliente
    at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:81)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:71)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47)
    at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:72)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.addCurrentElementToCollection(CollectionConverter.java:98)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:91)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:85)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:80)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    ... 22 more
Exception running application application.Main
2

1 Answer 1

1

Check your classpath A classnotfounderror Most of the time is an indicator that the class which is required is Not in the classpath

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, I had only added xstream-1.4.10.jar and xpp3_min-1.1.4c.jar to the classpath. Now I added xmlpull-1.1.3.1.jar and I have another error: Security framework of XStream not initialized, XStream is probably vulnerable. I'll edit the full error in the main post.
Please have a Look at the api‘s documentation. It‘s Most likely that You have To set up the xstream before using it. Also, have a look at stackoverflow.com/questions/44698296/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.