当前位置: 技术问答>java相关
一个关于NoClassDefFounderErr的问题
来源: 互联网 发布时间:2015-07-19
本文导语: 运行其他程序都正常,但在下面这个程序中出现 C:jenut2JavaExamples2>java com.davidflanagan.examples.io.FileLister Exception in thread "main" java.lang.NoClassDefFoundError: com/davidflanagan/exa mples/io/FileLister (wrong name: FileLister) a...
运行其他程序都正常,但在下面这个程序中出现
C:jenut2JavaExamples2>java com.davidflanagan.examples.io.FileLister
Exception in thread "main" java.lang.NoClassDefFoundError: com/davidflanagan/exa
mples/io/FileLister (wrong name: FileLister)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
不只是什么原因?下面是源码 (放不下,我在发一个贴子)
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DateFormat;
import java.util.Date;
public class FileLister extends Frame implements ActionListener, ItemListener {
private List list; // To display the directory contents in
private TextField details; // To display detail info in.
private Panel buttons; // Holds the buttons
private Button up, close; // The Up and Close buttons
private File currentDir; // The directory currently listed
private FilenameFilter filter; // An optional filter for the directory
private String[] files; // The directory contents
private DateFormat dateFormatter = // To display dates and time correctly
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
public FileLister(String directory, FilenameFilter filter) {
super("File Lister"); // Create the window
this.filter = filter; // Save the filter, if any
// Destroy the window when the user requests it
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { dispose(); }
});
list = new List(12, false); // Set up the list
list.setFont(new Font("MonoSpaced", Font.PLAIN, 14));
list.addActionListener(this);
list.addItemListener(this);
details = new TextField(); // Set up the details area
details.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
details.setEditable(false);
buttons = new Panel(); // Set up the button box
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 5));
buttons.setFont(new Font("SansSerif", Font.BOLD, 14));
up = new Button("Up a Directory"); // Set up the two buttons
close = new Button("Close");
up.addActionListener(this);
close.addActionListener(this);
buttons.add(up); // Add buttons to button box
buttons.add(close);
this.add(list, "Center"); // Add stuff to the window
this.add(details, "North");
this.add(buttons, "South");
this.setSize(500, 350);
listDirectory(directory); // And now list initial directory.
}
public void listDirectory(String directory) {
// Convert the string to a File object, and check that the dir exists
File dir = new File(directory);
if (!dir.isDirectory())
throw new IllegalArgumentException("FileLister: no such directory");
// Get the (filtered) directory entries
files = dir.list(filter);
// Sort the list of filenames. Prior to Java 1.2, you could use
// com.davidflanagan.examples.classes.Sorter.sort() to sort instead.
java.util.Arrays.sort(files);
// Remove any old entries in the list, and add the new ones
list.removeAll();
list.add("[Up to Parent Directory]"); // A special case entry
for(int i = 0; i
C:jenut2JavaExamples2>java com.davidflanagan.examples.io.FileLister
Exception in thread "main" java.lang.NoClassDefFoundError: com/davidflanagan/exa
mples/io/FileLister (wrong name: FileLister)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
不只是什么原因?下面是源码 (放不下,我在发一个贴子)
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DateFormat;
import java.util.Date;
public class FileLister extends Frame implements ActionListener, ItemListener {
private List list; // To display the directory contents in
private TextField details; // To display detail info in.
private Panel buttons; // Holds the buttons
private Button up, close; // The Up and Close buttons
private File currentDir; // The directory currently listed
private FilenameFilter filter; // An optional filter for the directory
private String[] files; // The directory contents
private DateFormat dateFormatter = // To display dates and time correctly
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
public FileLister(String directory, FilenameFilter filter) {
super("File Lister"); // Create the window
this.filter = filter; // Save the filter, if any
// Destroy the window when the user requests it
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { dispose(); }
});
list = new List(12, false); // Set up the list
list.setFont(new Font("MonoSpaced", Font.PLAIN, 14));
list.addActionListener(this);
list.addItemListener(this);
details = new TextField(); // Set up the details area
details.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
details.setEditable(false);
buttons = new Panel(); // Set up the button box
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 5));
buttons.setFont(new Font("SansSerif", Font.BOLD, 14));
up = new Button("Up a Directory"); // Set up the two buttons
close = new Button("Close");
up.addActionListener(this);
close.addActionListener(this);
buttons.add(up); // Add buttons to button box
buttons.add(close);
this.add(list, "Center"); // Add stuff to the window
this.add(details, "North");
this.add(buttons, "South");
this.setSize(500, 350);
listDirectory(directory); // And now list initial directory.
}
public void listDirectory(String directory) {
// Convert the string to a File object, and check that the dir exists
File dir = new File(directory);
if (!dir.isDirectory())
throw new IllegalArgumentException("FileLister: no such directory");
// Get the (filtered) directory entries
files = dir.list(filter);
// Sort the list of filenames. Prior to Java 1.2, you could use
// com.davidflanagan.examples.classes.Sorter.sort() to sort instead.
java.util.Arrays.sort(files);
// Remove any old entries in the list, and add the new ones
list.removeAll();
list.add("[Up to Parent Directory]"); // A special case entry
for(int i = 0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!