2012-11-23 5 views
1

XStream을 사용하여 파일에 데이터베이스를 저장 한 다음 나중에 XStream을 사용하여 다시 열고 이전에 있던 객체로 역 직렬화하려고합니다. 데이터베이스는 테이블의 arraylist로 구성되며 데이터 클래스의 arraylist로 구성되며 데이터 클래스에는 객체의 arraylist가 포함됩니다. 기본적으로 SQL 컴파일러를 만들려고합니다. 현재 load 메서드의 마지막 행 때문에 java.lang.NoSuchMethodError가 발생합니다. 여기에 내가 가진 무엇 :NoSuchMethodError (Java에서 XStream 사용)

저장 방법

public void save(Database DB){ 
    File file = new File(DB.getName().toUpperCase() + ".xml"); 

    //Test sample 
    DB.createTable("TBL1(character(a));"); 
    DB.tables.getTable("TBL1").rows.add(new DataList()); 
    DB.tables.getTable("TBL1").rows.getRow(0).add(10); 

    XStream xstream = new XStream(); 
    //Database 
    xstream.alias("Database", Database.class); 
    //Tables 
    xstream.alias("Table", Table.class); 
    //Rows 
    xstream.alias("Row", DataList.class); 
    //Data 
    //xstream.alias("Data", Object.class); 

    //String xml = xstream.toXML(DB); 
    Writer writer = null; 
    try { 
     writer = new FileWriter(file); 
     writer.write(xstream.toXML(DB)); 
     writer.close(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    }   
} 

로드 방법

public void Load(String dbName){ 
    XStream xstream = new XStream(); 

    BufferedReader br; 
    StringBuffer buff = null; 
    try { 
     br = new BufferedReader(new FileReader(dbName + ".xml")); 
     buff = new StringBuffer(); 
     String line; 
     while((line = br.readLine()) != null){ 
      buff.append(line); 
     } 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    database = (Database)xstream.fromXML(buff.toString()); 
} 

스택 추적

Exception in thread "main" java.lang.NoSuchMethodError:  
org.xmlpull.v1.XmlPullParserFactory.newInstance(Ljava/lang/String;Ljava/lang/Class;)Lorg/xmlpull/v1/XmlPullParserFactory; 
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:57) 
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904) 
at dbt.Load(dbt.java:255) 
at dbt.checktypestatement(dbt.java:88) 
at dbt.main(dbt.java:45) 

참조 된 (라이브러리의 일부를 변경 라이브러리 후 : XStream을, xpp3, 및 xmlpull)이 런타임에 얻을 오류 :

Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Row : Row 
---- Debugging information ---- 
message    : Row 
cause-exception  : com.thoughtworks.xstream.mapper.CannotResolveClassException 
cause-message  : Row 
class    : java.util.ArrayList 
required-type  : java.util.ArrayList 
converter-type  : com.thoughtworks.xstream.converters.collections.CollectionConverter 
path    : /Database/tables/tables/Table/rows/rows/Row 
line number   : 1 
class[1]   : RowList 
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter 
class[2]   : Table 
class[3]   : TableList 
class[4]   : Database 
version    : null 
------------------------------- 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) 
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71) 
at com.thoughtworks.xstream.converters.collections.CollectionConverter.addCurrentElementToCollection(CollectionConverter.java:79) 
at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:72) 
at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:66) 
at com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306) 
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 
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:1058) 
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904) 
at dbt.load(dbt.java:257) 
at dbt.checktypestatement(dbt.java:87) 
at dbt.main(dbt.java:44) 
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: Row 
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56) 
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) 
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55) 

... 
+1

스택 추적을 게시하십시오. – Andy

+0

애플리케이션 클래스 경로를 검사하여'XStream' Jar의 여러 버전이 있는지 확인할 수 있습니까? –

+0

추적? 컴파일 시간 또는 런타임 오류입니까? 거기에 충분한 정보가 없습니다. –

답변

0

저장 방법에서 xstream.alias 메소드를 주석 처리하여 문제를 해결할 수있었습니다.