[Gvsig_english] Errors while modifying a dbasefile

Matthieu Voorons matthieu.voorons at gmail.com
Tue May 22 17:32:25 CEST 2007


Hi list,
I'm still trying to play with a dbf file. I don't have any problem to 
read the file and make some basic queries, but I have some problems when 
I try to modify and save the dbasefile.
I get a null pointer exception when I try to add a new record to the dbase.
    String expression = insert into properties(NAME,STREET,CITY,ZIP) 
values (myname,myroad,mycity,88818);
    DataSource ds = sds.getDataSourceFactory().executeSQL(expression, 
DataSourceFactory.AUTOMATIC_OPENING); //here I get a nullpointerexception
Do I have to specify somewhere that I am in editing mode ? Is there 
another way to simply add a record to a dbase?

What should I do if I want to save the modified dbasefile (in a new file 
or not) ?
I tried :
            SelectableDataSource sds = new 
SelectableDataSource(dataSource);//the data to save
            EditableAdapter auxea = new EditableAdapter();
            auxea.setOriginalDataSource(sds);
            DbfWriter writer = new DbfWriter();
            writer.setFile(new File("c:\\savedDbf.dbf"));
            try {
                auxea.saveEdits(writer, EditionEvent.ALPHANUMERIC);
            } catch (EditionException ex) {
                ex.printStackTrace();
            }
but I get a nullpointerexception on the line auxea.saveEdits
Exception in thread "main" java.lang.NullPointerException
        at 
com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter.getFields(DbfWriter.java:229)
        at 
com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter.alterTable(DbfWriter.java:180)
        at 
com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter.preProcess(DbfWriter.java:80)
        at 
com.iver.cit.gvsig.fmap.edition.EditableAdapter.saveEdits(EditableAdapter.java:316)

Is there someting I'm missing there?
Thanks for your replies, regards,
Matthieu


More information about the Gvsig_internacional mailing list