Exception in thread "AWT-EventQueue-0" java.lang.N

0

W trakcie kompilacji wyskakuje mi następujący ciąg błędów:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/batik/swing/JSVGCanvas
at ZloG.ZloG_GUI.<init>(ZloG_GUI.java:87)
at ZloG.ZloG.<init>(ZloG.java:28)
at ZloG.ZloG$1.run(ZloG.java:66)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Parametry pracy to
JBuilder + JDK 1.6.0-b105 (ale probowalem tez z 1.5) + batik 1.6, do ktorego scieżke mam w CLASSPATH i wgranej bibliotece w JBuilderze dołączoną do projektu ZloG.

Chodzi o to że w moim programie którego kod dołączam na końcu zrobionego w SWINGU w momencie dodania konstruktora:
JSVGCanvas svgCanvas = new JSVGCanvas();
wyskakuje napisany wyżej błąd. Ale gdy w innej klasie w tym samym projekcie uruchomie przykładowy program ze strony batika, wyswietlający mape svg w JSVGCanvas, nie ma żadnych błędów i wszystko ładnie smiga.

Ktoś ma jakiś pomysł. Wiem ze to może być banalne rozwiązanie, i na stronach z google, dowiedziałem się ze to problem z klasą ładującą klase org/apache/batik/swing/JSVGCanvas. Ale w innych przypadkach ktoś np zmienił JDK i niby działało. Poza tym u mnie działa ale w innym pliku.

PROGRAM GŁÓWNY:
package ZloG;

import java.awt.;
import java.awt.event.
;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.io.IOException;
import javax.swing.JFileChooser;
import java.io.File;
import java.util.Scanner;
import javax.swing.ProgressMonitorInputStream;
import java.io.FileInputStream;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import javax.swing.JTabbedPane;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Font;

import java.awt.;
import java.awt.event.
;
import java.io.;
import javax.swing.
;

import org.apache.batik.swing.JSVGCanvas;

/**

  • Title: ZloG - Nawigacja Zliczeniowa
  • ription: Program służący do prowadzenia nawigacji zliczeniowej na
  • podstawie danych z kompasu i logu</p>
  • Copyright: Copyright (c) 2007
  • Company: SEM WETI PG
  • @author Marcin Milecki
  • @version 0.01
    */
    public class ZloG_GUI extends JFrame {
    //zmienne prywatne
    private int i;
    private int k;
    private int nr_obrazka;

    JPanel contentPane;
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenuFile = new JMenu();
    JMenuItem jMenuFileExit = new JMenuItem();
    JMenu jMenuHelp = new JMenu();
    JMenuItem jMenuHelpAbout = new JMenuItem();
    JToolBar jToolBar = new JToolBar();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JMenu jMenuTools = new JMenu();
    JMenuItem jMenuSave = new JMenuItem();
    JMenu jMenu2 = new JMenu();
    JMenuItem jMenuOpen = new JMenuItem();
    JMenuItem jMenuConfigure = new JMenuItem();
    JTabbedPane jTabUp = new JTabbedPane();
    JPanel jPLog = new JPanel();
    JPanel jPCompass = new JPanel();
    JPanel jPGraph = new JPanel();
    JTabbedPane jTabDown = new JTabbedPane();
    JPanel jPMessageBox = new JPanel();
    JPanel jPMap = new JPanel();
    JPanel jPanelDL = new JPanel();
    JLabel jLautor = new JLabel();
    JLabel jLversion = new JLabel();
    JLabel jLcompiled = new JLabel();
    JPanel jPanelRD = new JPanel(); //dodanie Logo do Okna programu
    JLabel jLConnect = new JLabel();
    JTextArea jTATerminal = new JTextArea();
    JSVGCanvas svgCanvas = new JSVGCanvas();
    //Wczytywanie obrazkow
    ImageIcon image1 = new ImageIcon(ZloG_GUI.class.getResource(
    "openFile.png"));
    ImageIcon image2 = new ImageIcon(ZloG_GUI.class.getResource(
    "closeFile.png"));
    ImageIcon image3 = new ImageIcon(ZloG_GUI.class.getResource("help.png"));
    Image image_connect = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo.png"));
    Image image_notconn = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_n.png"));
    Image image_notlog = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_l.png"));
    Image image_notcom = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_k.png"));
    Image image_notgps = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_g.png"));
    Image image_notgpslog = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_gl.png"));
    Image image_notgpscom = Toolkit.getDefaultToolkit().getImage(ZloG_GUI.class.getResource("ZLoG_logo_gk.png")); // jSVGCanvas1.
    JButton jButton4 = new JButton();

    public ZloG_GUI() {
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().
    getResource("ZLoG_logo.png")));
    try {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    jbInit();
    } catch (Exception exception) {
    exception.printStackTrace();
    }
    }

    /**

    • Component initialization.
    • @throws java.lang.Exception
      */
      private void jbInit() throws Exception {
      contentPane = (JPanel) getContentPane();
      contentPane.setLayout(null);
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      setSize(new Dimension(screenSize.width-10,screenSize.height-10));
      setTitle("ZLoG - Nawigacja Zliczeniowa");
      jMenuFile.setText("Plik");
      jMenuFileExit.setText("Koniec");
      jMenuFileExit.addActionListener(new
      ZloG_GUI_jMenuFileExit_ActionAdapter(this));
      jMenuHelp.setText("Pomoc");
      jMenuHelpAbout.setText("O programie");
      jMenuHelpAbout.addActionListener(new
      ZloG_GUI_jMenuHelpAbout_ActionAdapter(this));
      jMenuOpen.setText("Otwórz");
      jMenuOpen.addActionListener(new ZloG_GUI_jMenuOpen_actionAdapter(this));
      jMenuSave.setText("Zapisz");
      jMenuTools.setText("Narzędzia");
      jMenuConfigure.setText("Opcje");
      // jMenuConfigure.addActionListener(new
      // ZloG_GUI_jMenuConfigure_actionAdapter(this));
      jTabUp.setBackground(Color.black);
      jTabUp.setForeground(Color.orange);
      jTabUp.setBorder(BorderFactory.createLineBorder(Color.black));
      jTabUp.setMaximumSize(new Dimension(320, 370));
      jTabUp.setPreferredSize(new Dimension(100, 200));
      jTabUp.setActionMap(null);
      jTabUp.setBounds(new Rectangle(11, 40, 1248, 619));
      jToolBar.setBounds(new Rectangle(0, 0, 1141, 39));
      jTabDown.setFont(new java.awt.Font("Tahoma", Font.PLAIN, 9));
      jTabDown.setAlignmentX((float) 1.0);
      jTabDown.setPreferredSize(new Dimension(10, 38));
      jTabDown.setBounds(new Rectangle(129, 658, 1031, 61));
      jPLog.setToolTipText("");
      jPanelDL.setBorder(BorderFactory.createLineBorder(Color.black));
      jPanelDL.setBounds(new Rectangle(13, 662, 112, 53));
      jPanelDL.setLayout(null);
      jLautor.setText("autor: Marcin Milecki");
      jLautor.setBounds(new Rectangle(9, 34, 97, 14));
      jLversion.setText(" ZLoG version 0.01");
      jLversion.setBounds(new Rectangle(6, 2, 100, 14));
      jLcompiled.setText(" compiled 28.03.2007");
      jLcompiled.setBounds(new Rectangle(5, 18, 103, 14));
      jPanelRD.setBounds(new Rectangle(1165, 666, 95, 60));
      jPanelRD.setLayout(null);
      jLConnect.setFont(new java.awt.Font("Tahoma", Font.PLAIN, 9));
      jLConnect.setText("not connected");
      jLConnect.setBounds(new Rectangle(17, 45, 60, 12));
      jButton4.setText("jButton4");
      jMenuBar1.add(jMenuFile);
      jMenuBar1.add(jMenuTools);
      jMenuFile.addSeparator();
      jMenuFile.add(jMenuOpen);
      jMenuFile.add(jMenuSave);
      jMenuFile.add(jMenuFileExit);
      jMenuBar1.add(jMenuHelp);
      jMenuHelp.add(jMenuHelpAbout);
      setJMenuBar(jMenuBar1);
      jButton1.setIcon(image1);
      jButton1.setToolTipText("Otwórz plik");
      jButton2.setIcon(image2);
      jButton2.setToolTipText("Zamknij plik");
      jButton3.setIcon(image3);
      jButton3.setToolTipText("Pomoc");
      jToolBar.add(jButton1);
      jToolBar.add(jButton2);
      jToolBar.add(jButton3);
      contentPane.add(jPanelRD);
      jPanelRD.add(jLConnect);
      contentPane.add(jPanelDL);
      jPanelDL.add(jLversion);
      jPanelDL.add(jLcompiled);
      jPanelDL.add(jLautor);
      contentPane.add(jTabDown);
      contentPane.add(jTabUp);
      contentPane.add(jToolBar);
      jMenuTools.add(jMenuConfigure);
      jTabUp.add(jPLog, "Log");
      jTabUp.add(jPCompass, "Kompas");
      jTabUp.add(jPMap, "Mapa");
      jPMap.add(jButton4);
      jTabDown.add(jTATerminal, "Konsola");
      jTabDown.add(jPMessageBox, "Wyjście");
      jTabUp.add(jPGraph, "Wykresy");
      // jPanelRD.prepareImage(image4,50,50,null);
      //zmienne
      nr_obrazka=1;

    }

    /**

    • File | Exit action performed.
    • @param actionEvent ActionEvent
      */
      void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
      System.exit(0);
      }

    /**

    • Help | About action performed.
    • @param actionEvent ActionEvent
      */
      void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
      ZloG_GUI_AboutBox dlg = new ZloG_GUI_AboutBox(this);
      Dimension dlgSize = dlg.getPreferredSize();
      Dimension frmSize = getSize();
      Point loc = getLocation();
      dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
      (frmSize.height - dlgSize.height) / 2 + loc.y);
      dlg.setModal(true);
      dlg.pack();
      dlg.setVisible(true);
      }

    public void jMenuOpen_actionPerformed(ActionEvent e) {
    try {
    openFile();
    } catch (IOException exception) {
    exception.printStackTrace();
    }
    }

    public void openFile() throws IOException
    {
    System.out.println("in openFile");
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    chooser.setFileFilter(
    new javax.swing.filechooser.FileFilter()
    {
    public boolean accept(File f)
    {
    String fname = f.getName().toLowerCase();
    return fname.endsWith(".txt") || f.isDirectory();
    }
    public String getDescription()
    {
    return "Text Files";
    }
    });

    int r = chooser.showOpenDialog(this);
    if (r != JFileChooser.APPROVE_OPTION) return;
    final File f = chooser.getSelectedFile();

    FileInputStream fileIn = new FileInputStream(f);
    ProgressMonitorInputStream progressIn
    = new ProgressMonitorInputStream(this, "Reading " + f.getName(), fileIn);
    final Scanner in = new Scanner(progressIn);

    // monitorowana operacja musi być wykonywana w osobnym wątku

Runnable readRunnable = new
Runnable()
{
public void run()
{
final JTextArea textArea = new JTextArea();

     while (in.hasNextLine())
     {
        String line = in.nextLine();
        textArea.append(line);
        textArea.append("\n");
     }
     in.close();

     // aktualizuje zawartość panela w wątku obsługi zdarzeń
     // interfejsu użytkownika
     EventQueue.invokeLater(new
        Runnable()
        {
           public void run()
           {
              setContentPane(new JScrollPane(textArea));
              validate();
           }
        });

  }

};

 Thread readThread = new Thread(readRunnable);
 readThread.start();

  }

class ZloG_GUI_jMenuOpen_actionAdapter implements ActionListener {
    private ZloG_GUI adaptee;
    ZloG_GUI_jMenuOpen_actionAdapter(ZloG_GUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jMenuOpen_actionPerformed(e);
    }
}

class ZloG_GUI_jMenuFileExit_ActionAdapter implements ActionListener {
    ZloG_GUI adaptee;

    ZloG_GUI_jMenuFileExit_ActionAdapter(ZloG_GUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent actionEvent) {
        adaptee.jMenuFileExit_actionPerformed(actionEvent);
    }
}

class ZloG_GUI_jMenuHelpAbout_ActionAdapter implements ActionListener {
    ZloG_GUI adaptee;

    ZloG_GUI_jMenuHelpAbout_ActionAdapter(ZloG_GUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent actionEvent) {
        adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
    }

}
//Funkcja rysująca elementry graficzne w trakcie odświeżania strony
public void paint (Graphics g)
{

 super.paint(g);
 //System.out.println("w śrdoku paint(g)");
 switch (nr_obrazka)
   {
   case 0:
   g.drawImage(image_notconn,1200,730,null);
   jLConnect.setText("not connected");
   break;
   case 1:
   g.drawImage(image_connect,1200,730,null);
   jLConnect.setText("   connected");
   break;
  }
 }

public void jMenuConfigure_actionPerformed(ActionEvent e) {
        ZloG_GUI_ConfigBox dlg = new ZloG_GUI_ConfigBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                (frmSize.height - dlgSize.height) / 2 + loc.y);
        dlg.setModal(true);
        dlg.pack();
        dlg.setVisible(true);

}

}
/*
class ZloG_GUI_jMenuConfigure_actionAdapter implements ActionListener {
private ZloG_GUI adaptee;
ZloG_GUI_jMenuConfigure_actionAdapter(ZloG_GUI adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
    adaptee.jMenuConfigure_actionPerformed(e);
}

}
*/


PROGRAM PRZYKŁADOWY BATIKA:
package ZloG;

import java.awt.;
import java.awt.event.
;
import java.io.;
import javax.swing.
;

import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
/**

  • Title: ZloG - Nawigacja Zliczeniowa
  • ription: Program służący do prowadzenia nawigacji zliczeniowej na
  • podstawie danych z kompasu i logu</p>
  • Copyright: Copyright (c) 2007
  • Company: SEM WETI PG
  • @author Marcin Milecki
  • @version 0.01
    */
    public class batik_proby3 {

    public static void main(String[] args) {
    JFrame f = new JFrame("Batik");
    batik_proby3 app = new batik_proby3(f);
    f.getContentPane().add(app.createComponents());
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    f.setSize(400, 400);
    f.setVisible(true);
    }

    JFrame frame;
    JButton button = new JButton("Load...");
    JLabel label = new JLabel();
    JSVGCanvas svgCanvas = new JSVGCanvas();

    public batik_proby3(JFrame f) {
    frame = f;
    }

    public JComponent createComponents() {
    final JPanel panel = new JPanel(new BorderLayout());
    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p.add(button);
    p.add(label);
    panel.add(p, BorderLayout.NORTH);
    panel.add(svgCanvas, BorderLayout.CENTER);

    // Set the button action.
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser fc = new JFileChooser(".");
            int choice = fc.showOpenDialog(panel);
            if (choice == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                try {
                    svgCanvas.setURI(f.toURL().toString());
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    
    // Set the JSVGCanvas listeners.
    svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
        public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
            label.setText("Document Loading...");
        }
        public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
            label.setText("Document Loaded.");
        }
    });
    
    svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
        public void gvtBuildStarted(GVTTreeBuilderEvent e) {
            label.setText("Build Started...");
        }
        public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
            label.setText("Build Done.");
            frame.pack();
        }
    });
    
    svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
        public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
            label.setText("Rendering Started...");
        }
        public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
            label.setText("");
        }
    });
    
    return panel;

    }
    }

Z góry dzięki za odpowiedź.

0

Już sprawe rozwiązałam. Mianowicie w JBuilderze trzeba dodać biblioteki do kompilacji i do schematu uruchomieniowego oddzielnie. Stąd ten błąd.

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0