NoSuchMethodError in Java using XStream

Posted by Brad Germain on Stack Overflow See other posts from Stack Overflow or by Brad Germain
Published on 2012-11-23T23:01:04Z Indexed on 2012/11/23 23:03 UTC
Read the original article Hit count: 389

Filed under:
|

I'm trying to save a database into a file using XStream and then open it again later using XStream and deserialize it back into the objects it was in previously. The database consists of an arraylist of tables, which consists of an arraylist of a data class where the data class contains an arraylist of objects. I'm basically trying to create an sql compiler. I'm currently getting a java.lang.NoSuchMethodError because of the last line in the load method. Here's what I have:

Save Method

    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();
    }        
}

Load Method

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());
}

© Stack Overflow or respective owner

Related posts about java

Related posts about xstream