Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Come mai mi da quest'eccezione?!?

    Con Dos faccio javac TextEditor.java e mi crea il file class.

    ma quando vado a fare java TextEditor mi da il seguente errore:

    Exception in thread "main" java.lang.NoClassDefFoundError: TextEditor



    Questo è il codice TextEditor.java utilizzato:

    codice:
     
    
    import javax.swing.*; 
    
    import javax.swing.text.*; 
    
    import java.awt.*; 
    
    import java.awt.event.*; 
    
    import java.io.*; 
    
    public class TextEditor extends JFrame { 
    
      private JTextComponent editor; 
    
      private JFileChooser fileChooser; 
    
      protected Action loadAction; 
    
      protected Action saveAction; 
    
      protected Action cutAction; 
    
      protected Action copyAction; 
    
      protected Action pasteAction; 
    
      public TextEditor() { 
    
        super("TextEditor"); 
    
        setSize(300,300); 
    
        createActions();  
    
        JMenuBar menuBar = createMenuBar(); 
    
        JToolBar toolbar = createToolBar(); 
    
        editor = createEditor(); 
    
        JComponent centerPanel = createCenterComponent(); 
    
        getContentPane().add(BorderLayout.NORTH,toolbar); 
    
        getContentPane().add(BorderLayout.CENTER,centerPanel); 
    
        setJMenuBar(menuBar); 
    
        fileChooser = new JFileChooser(); 
    
        setVisible(true);  
    
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    
     } 
    
      protected void createActions() { 
    
        loadAction = new AbstractAction("Open", new ImageIcon("Open24.gif")) { 
    
          public void actionPerformed(ActionEvent e) { 
    
            loadText(); 
    
          } 
    
        }; 
    
        saveAction = new AbstractAction("Save", new ImageIcon("Save24.gif")) { 
    
          public void actionPerformed(ActionEvent e) { 
    
            saveText(); 
    
          } 
    
        };  
    
        cutAction = new AbstractAction("Cut", new ImageIcon("Cut24.gif")) { 
    
          public void actionPerformed(ActionEvent e) { 
    
            editor.cut(); 
    
          } 
    
        };  
    
        copyAction = new AbstractAction("Copy", new ImageIcon("Copy24.gif")) { 
    
          public void actionPerformed(ActionEvent e) { 
    
            editor.copy(); 
    
          } 
    
        };  
    
        pasteAction = new AbstractAction("Paste", new ImageIcon("Paste24.gif")) { 
    
          public void actionPerformed(ActionEvent e) { 
    
            editor.paste(); 
    
          } 
    
        };  
    
      } 
    
      protected JToolBar createToolBar() { 
    
        JToolBar tb = new JToolBar(); 
    
        tb.add(loadAction); 
    
        tb.add(saveAction); 
    
        tb.addSeparator(); 
    
        tb.add(cutAction); 
    
        tb.add(copyAction); 
    
        tb.add(pasteAction); 
    
        return tb; 
    
      } 
    
      protected JMenuBar createMenuBar() { 
    
        JMenu menu = new JMenu("Menu"); 
    
          menu.add(loadAction); 
    
          menu.add(saveAction); 
    
          menu.addSeparator(); 
    
          menu.add(cutAction); 
    
          menu.add(copyAction); 
    
          menu.add(pasteAction); 
    
        JMenuBar menuBar = new JMenuBar(); 
    
        menuBar.add(menu); 
    
        return menuBar; 
    
      } 
    
      protected JComponent createCenterComponent() { 
    
        if(editor == null) 
    
          editor = createEditor(); 
    
        return new JScrollPane(editor); 
    
      } 
    
      protected JTextComponent createEditor() { 
    
        return new JTextArea(); 
    
      } 
    
      public void loadText() { 
    
        int response = fileChooser.showOpenDialog(this); 
    
        if(response==JFileChooser.APPROVE_OPTION) { 
    
          try { 
    
            File f = fileChooser.getSelectedFile(); 
    
            Reader in = new FileReader(f); 
    
            editor.read(in,null); 
    
            setTitle(f.getName()); 
    
          } 
    
          catch(Exception e) {} 
    
        } 
    
      } 
    
      public void saveText() { 
    
        int response = fileChooser.showSaveDialog(this); 
    
        if(response==JFileChooser.APPROVE_OPTION) { 
    
          try { 
    
            File f = fileChooser.getSelectedFile(); 
    
            Writer out = new FileWriter(f); 
    
            editor.write(out); 
    
            setTitle(f.getName()); 
    
          } 
    
          catch(Exception e) {} 
    
        } 
    
      } 
    
      public static void main(String argv[]) { 
    
        TextEditor t = new TextEditor(); 
    
      } 
    
    }

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: Come mai mi da quest'eccezione?!?

    Originariamente inviato da xxdavide84xx
    Con Dos faccio javac TextEditor.java e mi crea il file class.

    ma quando vado a fare java TextEditor mi da il seguente errore:

    Exception in thread "main" java.lang.NoClassDefFoundError: TextEditor
    Imposta la variabile di ambiente CLASSPATH in modo che contenga il punto '.' (directory corrente) o lancia con:

    java -cp . TextEditor

    queste sono le basi.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3

    Re: Re: Come mai mi da quest'eccezione?!?

    Originariamente inviato da andbin
    Imposta la variabile di ambiente CLASSPATH in modo che contenga il punto '.' (directory corrente) o lancia con:

    java -cp . TextEditor

    queste sono le basi.
    Scusa, ma sono all'inizio e si vede purtroppo!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.