Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Another Problem with java.lang.NoClassDefFoundError

    Hello. I'm working in NetBeans. When I run my project, I get the following error:

    "Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: textfiles/ReadFile
    at form_control_lession.FormObjects.menuItemOpenActio nPerformed(FormObjects.java: 295) - etc....
    ....
    Caused by: java.lang.ClassNotFoundException: textfiles.ReadFile
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366) etc....."

    My program uses this class ReadFile in the textfiles package. The program includes this import statement:
    Java Code:
    package form_control_lession;
    
    import java.io.IOException;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import textfiles.ReadFile;
    
    public class FormObjects extends javax.swing.JFrame {
    and further in the program, referencing the ReadFile class:
    Java Code:
    try {           // displays a text file in the taOne text area.
                    ReadFile file_read = new ReadFile(file_name);
                    String[] aryLines = file_read.OpenFile();
                    String theText = ("");
                    int i;
                    for (i =0; i < aryLines.length; i++) {
                        theText = theText + aryLines[i] + '\n';
                    }
                    
                    taOne.setText(theText);
                }
    If I understand the error messages correctly, java can't find this textfiles.ReadFile class. Can anyone help me fix this?

    Thank you.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default Re: Another Problem with java.lang.NoClassDefFoundError

    ClassNotFoundException: textfiles.ReadFile
    Where is the definition for the class that is not found? Is the .class file in a folder on disk or in a jar file?
    The definition must be available via the classpath so the JVM can find it.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Another Problem with java.lang.NoClassDefFoundError

    Hello. Thanks for your reply.

    All files reside on my computer's C:/ drive - FormObjects (has main method), and ReadFiles (in the package textfiles). None of this are .JAR files. Package textfiles is a folder, and ReadFiles is a class file.

    Perhaps I need to include the path to package textfiles in the import statement. I will try that and report back.

    Thanks again.

  4. #4
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Another Problem with java.lang.NoClassDefFoundError

    Update: I might have found my problem - which of course exists between my ears!!!

    Because this is the second time I have written this program, I have two folders referencing this program. So I have confused which folder I am working in. I will correct this situation and if I am still having problems I will return to the forum with more questions.

    Thanks.

Similar Threads

  1. java.lang.NoClassDefFoundError:
    By Gowramma in forum New To Java
    Replies: 0
    Last Post: 05-02-2012, 08:57 PM
  2. Replies: 5
    Last Post: 06-02-2010, 01:05 PM
  3. Replies: 3
    Last Post: 06-01-2010, 03:01 PM
  4. java.lang.NoClassDefFoundError:
    By jeepcreep11 in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 11:58 AM
  5. java.lang.NoClassDefFoundError
    By J_a_y in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •