[Gvsig_desarrolladores] Error grave de la aplicación. Es conveniente que salgas de la aplicación. java.lang.NoClassDefFoundError: jxl/write/WritableCell
Francisco José Peñarrubia
fpenarru en gmail.com
Mie Ene 25 12:35:36 CET 2012
Lo correcto sería poner
<dependsplugin-name=/"org.gvsig.tableExport">
/El nombre del plugin es el nombre del directorio que contiene todo en
_fwAndami/extensiones/
Saludos.
Fran.
El 25/01/2012 12:32, Antonio Araque escribió:
>
> Buenas Francisco,
>
> Se me ha olvidado comentar que añado las dependencias a la extensión:
>
> <dependsplugin-name=/"org.gvsig.tableExport.xls"//>
>
> He intentado también incluir directamente el path a la clase jxl, pero
> nada.
>
> <dependsplugin-name=/"jxl.write.WritableCell"//>
>
> *De:*gvsig_desarrolladores-bounces en listserv.gva.es
> [mailto:gvsig_desarrolladores-bounces en listserv.gva.es] *En nombre de
> *Francisco José Peñarrubia
> *Enviado el:* miércoles, 25 de enero de 2012 12:29
> *Para:* Lista de Desarrolladores de gvSIG
> *Asunto:* Re: [Gvsig_desarrolladores] Error grave de la aplicación. Es
> conveniente que salgas de la aplicación.
> java.lang.NoClassDefFoundError: jxl/write/WritableCell
>
> Hola Antonio.
>
> Imagino que estás intentando acceder a cosas que son de extTableExport.
> Cuando tu extensión depende de otra, tienes que incluir en el
> config.xml la dependencia. Ejemplo:
>
> <depends plugin-name="com.iver.cit.gvsig"/>
>
> En tu caso, añade un depends con lo de tableExport.
>
> Espero que te sirva.
>
> Saludos.
>
> Fran.
>
> El 25/01/2012 12:19, Antonio Araque escribió:
>
> Hola, estoy intentando reutilizar la extensión extTableExport, para
> exportar la información alfanumérica de una capa a un Excel.
>
> Me he creado una clase con los métodos que necesito:
>
> *import*java.awt.Component;
>
> *import*java.io.File;
>
> *import*java.util.Iterator;
>
> *import*java.util.NoSuchElementException;
>
> *import*javax.swing.JFileChooser;
>
> *import*javax.swing.JOptionPane;
>
> *import*jxl.JXLException;
>
> *import*jxl.Workbook;
>
> *import*jxl.write.Label;
>
> *import*jxl.write.Number;
>
> *import*jxl.write.NumberFormats;
>
> *import*jxl.write.WritableCell;
>
> *import*jxl.write.WritableCellFormat;
>
> *import*jxl.write.WritableSheet;
>
> *import*jxl.write.WritableWorkbook;
>
> *import*com.hardcode.gdbms.driver.exceptions.ReadDriverException;
>
> *import*com.hardcode.gdbms.engine.data.driver.DriverException;
>
> *import*com.hardcode.gdbms.engine.values.DoubleValue;
>
> *import*com.hardcode.gdbms.engine.values.FloatValue;
>
> *import*com.hardcode.gdbms.engine.values.NullValue;
>
> *import*com.hardcode.gdbms.engine.values.NumericValue;
>
> *import*com.hardcode.gdbms.engine.values.Value;
>
> *import*com.iver.andami.PluginServices;
>
> *import*com.iver.cit.gvsig.fmap.drivers.FieldDescription;
>
> *import*com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
>
> *import*com.iver.cit.gvsig.fmap.layers.FBitSet;
>
> *import*com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
>
> *import*com.iver.cit.gvsig.project.documents.table.gui.Table;
>
> *import*com.iver.utiles.GenericFileFilter;
>
> *public**class*ExportarExcel {
>
> *private*WritableCellFormat floatFormat= *new*WritableCellFormat
> (NumberFormats./FLOAT/);
>
> *private*WritableCellFormat intFormat= *new*WritableCellFormat
> (NumberFormats./INTEGER/);
>
> *public*ExportarExcel(){
>
> }
>
> *public**void*exportToXLS(Table table) *throws*Exception{
>
> File file = *this*.askForFileName("xls","Excel");
>
> *if*(file == *null*){
>
> *return*;
>
> }
>
> exportToFile(table,file);
>
> }
>
> *public**void*exportToFile(Table table,File trgfile) *throws*Exception{
>
> SelectableDataSource source;
>
> ITableDefinition orgDef;
>
> *try*{
>
> source = table.getModel().getModelo().getRecordset();
>
> source.start();
>
> orgDef =
> table.getModel().getModelo().getTableDefinition();
>
> } *catch*(Exception e) {
>
> *throw**new*Exception("Error preparando la fuente", e); //
> *TODO*_intenacionalizacion_??
>
> }
>
> File file = *new*File(trgfile.getAbsoluteFile()+".tmp");
>
> WritableWorkbook workbook = Workbook./createWorkbook/(file);
>
> WritableSheet sheet = workbook.createSheet("First Sheet", 0);
>
> writeHeader(sheet,orgDef);
>
> *try*{
>
> SourceIterator iter = *new*SourceIterator(source);
>
> Value[] values;
>
> Value value;
>
> *int*row=1;
>
> *int*col;
>
> *while*(iter.hasNext()){
>
> values = iter.nextValues();
>
> *for*(col=0;col<values.length;col++){
>
> value = values[col];
>
> *if*(!(value *instanceof*NullValue)){
>
> sheet.addCell(getCell(row,col,value));
>
> }
>
> }
>
> row++;
>
> }
>
> workbook.write();
>
> workbook.close();
>
> } *catch*(Exception e) {
>
> *throw**new*Exception("Error generando fichero", e); //
> *TODO*_intenacionalizacion_??
>
> }
>
> file.renameTo(trgfile);
>
> *try*{
>
> source.stop();
>
> } *catch*(Exception e) {
>
> *throw**new*Exception("Error cerrando ficheros", e); //
> *TODO*_intenacionalizacion_??
>
> }
>
> }
>
> *private*File askForFileName(String ext,String extDescription){
>
> JFileChooser jfc = *new*JFileChooser();
>
> jfc.addChoosableFileFilter(*new*GenericFileFilter(ext,
>
> extDescription));
>
> *if*(jfc.showSaveDialog((Component) PluginServices./getMainFrame/())
> == JFileChooser./APPROVE_OPTION/) {
>
> File file=jfc.getSelectedFile();
>
> *if*(file == *null*){
>
> *return**null*;
>
> }
>
> *if*(file.exists()){
>
> *int*resp = JOptionPane./showConfirmDialog/(
>
> (Component)
> PluginServices./getMainFrame/(),PluginServices./getText/(*this*,"fichero_ya_existe_seguro_desea_guardarlo"),
>
>
> PluginServices./getText/(*this*,"guardar"), JOptionPane./YES_NO_OPTION/);
>
> *if*(resp != JOptionPane./YES_OPTION/) {
>
> *return**null*;
>
> }
>
> }
>
> String name = file.getAbsolutePath();
>
> *if*(!name.toLowerCase().endsWith("."+ext.toLowerCase())){
>
> file = *new*File(name + "."+ext);
>
> }
>
> *return*file;
>
> } *else*{
>
> *return**null*;
>
> }
>
> }
>
> *private*WritableCell getCell(*int*row, *int*col, Value value) {
>
> *if*(value *instanceof*NumericValue){
>
> *if*(value *instanceof*DoubleValue || value *instanceof*FloatValue){
>
> *return**new*Number(col,row,((NumericValue)value).doubleValue(),floatFormat);
>
> } *else*{
>
> *return**new*Number(col,row,((NumericValue)value).longValue(),intFormat);
>
> }
>
> } *else*{
>
> *return**new*Label(col,row,value.toString());
>
> }
>
> }
>
> *private**void*writeHeader(WritableSheet sheet, ITableDefinition
> orgDef) *throws*JXLException {
>
> FieldDescription[] fields = orgDef.getFieldsDesc();
>
> FieldDescription field;
>
> Label cell;
>
> *int*col;
>
> *for*(col=0;col<fields.length;col++){
>
> field = fields[col];
>
> cell=*new*Label(col,0,field.getFieldName());
>
> sheet.addCell(cell);
>
> }
>
> }
>
> *private**class*SourceIterator *implements*_Iterator_{
>
> *private**int*index;
>
> *private**long*count;
>
> *private*FBitSet selection= *null*;
>
> *private*SelectableDataSource source;
>
> *public*SourceIterator(SelectableDataSource source)
> *throws*DriverException, ReadDriverException{
>
> *this*.source= source;
>
> *if*(source.getSelection().cardinality()== 0){
>
> *this*.selection= *null*;
>
> *this*.index=0;
>
> *this*.count= source.getRowCount();
>
> } *else*{
>
> *this*.selection= source.getSelection();
>
> *this*.index=selection.nextSetBit(0);
>
> *this*.count= selection.cardinality();
>
> }
>
> }
>
> *public**void*remove() {
>
> *throw**new*UnsupportedOperationException();
>
> }
>
> *public**boolean*hasNext() {
>
> *if*(*this*.selection== *null*)
>
> *return**this*.index< *this*.count;
>
> *return**this*.index>= 0;
>
> }
>
> *public*Object next() {
>
> *try*{
>
> *if*(!hasNext()){
>
> *throw**new*NoSuchElementException();
>
> }
>
> *return**this*.nextValues();
>
> } *catch*(DriverException e) {
>
> *throw**new*RuntimeException(e);
>
> } *catch*(ReadDriverException e) {
>
> *throw**new*RuntimeException(e);
>
> }
>
> }
>
> *public*Value[] nextValues() *throws*DriverException,
> ReadDriverException {
>
> Value[] values = *this*.source.getRow(*this*.index);
>
> *if*(*this*.selection== *null*){
>
> *this*.index++;
>
> } *else*{
>
> *this*.index= *this*.selection.nextSetBit(*this*.index+ 1);
>
> }
>
> *return*values;
>
> }
>
> *public**long*_count()_{
>
> *return**this*.count;
>
> }
>
> }
>
> }
>
> He importado al build path de mi extensión la librería jxl-2.6.6.jar
> proveniente de extTableExport.
>
> El problema es que cuando llamo al constructor de la clase
> ExportarExcel, me aparece el siguiente error:
>
> WARN [AWT-EventQueue-1] (_PluginClassLoader.java:191_) -
> PluginLoaders[i] es nulo
>
> WARN [AWT-EventQueue-1] (_PluginClassLoader.java:191_) -
> PluginLoaders[i] es nulo
>
> DEBUG [AWT-EventQueue-1] (_NotificationManager.java:104_) - Error
> grave de la aplicación. Es conveniente que salgas de la aplicación.
>
> java.lang.NoClassDefFoundError: jxl/write/WritableCell
>
> at
> com.iver.cit.gvsig.myplugin.panels.PanelFiltro$FuncionalidadBoton.exportarXLS(_PanelFiltro.java:754_)
>
> at
> com.iver.cit.gvsig.myplugin.panels.PanelFiltro$FuncionalidadBoton.actionPerformed(_PanelFiltro.java:625_)
>
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
>
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown
> Source)
>
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
> Source)
>
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
>
> at
> javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
>
> at java.awt.Component.processMouseEvent(Unknown Source)
>
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
>
> at java.awt.Component.processEvent(Unknown Source)
>
> at java.awt.Container.processEvent(Unknown Source)
>
> at java.awt.Component.dispatchEventImpl(Unknown Source)
>
> at java.awt.Container.dispatchEventImpl(Unknown Source)
>
> at java.awt.Component.dispatchEvent(Unknown Source)
>
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
>
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
>
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
>
> at java.awt.Container.dispatchEventImpl(Unknown Source)
>
> at java.awt.Window.dispatchEventImpl(Unknown Source)
>
> at java.awt.Component.dispatchEvent(Unknown Source)
>
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
>
> at
> com.iver.andami.ui.AndamiEventQueue.dispatchEvent(_AndamiEventQueue.java:58_)
>
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
> Source)
>
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
>
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
> Source)
>
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>
> at java.awt.EventDispatchThread.run(Unknown Source)
>
> Caused by: _java.lang.ClassNotFoundException_: Error leyendo
> fichero:jxl.write.WritableCell
>
> at
> com.iver.andami.plugins.PluginClassLoader.loadClass(_PluginClassLoader.java:251_)
>
> at java.lang.ClassLoader.loadClass(Unknown Source)
>
> ... 28 more
>
> Me está dando el error de que no encuentra la clase
> jxl.write.WritableCell, pero no entiendo el porqué del error, porque
> como he comentado anteriormente tengo incluido en el build Path el jar
> que contiene la clase WritableCell en jxl.write.
>
> Por más vueltas que le doy, no consigo solucionarlo. Alguien sabe a
> qué puede ser debido??
>
> Gracias.
>
> Un saludo.
>
> Antonio Araque.
>
>
>
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en listserv.gva.es <mailto:gvSIG_desarrolladores en listserv.gva.es>
> Para ver histórico de mensajes, editar sus preferencias de usuario o darse de baja en esta lista, acuda a la siguiente dirección:http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores
>
>
>
> --
> Fran Peñarrubia
> Scolab
> www.scolab.es <http://www.scolab.es>
>
> Asociación gvSIG
> www.gvsig.com <http://www.gvsig.com>
>
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en listserv.gva.es
> Para ver histórico de mensajes, editar sus preferencias de usuario o darse de baja en esta lista, acuda a la siguiente dirección: http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores
--
Fran Peñarrubia
Scolab
www.scolab.es
Asociación gvSIG
www.gvsig.com
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20120125/003c0657/attachment.htm
Más información sobre la lista de distribución gvSIG_desarrolladores