Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Main class Error

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Main class Error

    Hi, I have got a main class error, may i know what'swrong please?
    // Driver for parser
    package myparser;
     
    import java.io.*;
    import java_cup.runtime.Symbol;
    import static myparser.Main.do_debug_parse;
     
     
     
     
     
    //package myparser;
    //import java_cup.runtime.*;
    class Main {
     
      static boolean do_debug_parse = true;
     
      static public void main(String[] args) throws java.io.IOException {
          File infile = new File("C://Users//ASUS//Documents//NetBeansProjects//myparser_proj//myparser//myparser//input.txt");
         //parser parser_obj = new parser(new Yylex(fin));
          FileInputStream fin = null;
          try
          {
              fin = new FileInputStream(infile);
     
              /* create a parsing object */
              parser parser_obj = new parser(new Yylex(fin));
     
              Symbol parse_tree = null;
              if (do_debug_parse)
                  parse_tree = parser_obj.debug_parse();
              else
                  parse_tree = parser_obj.parse();
              System.out.println("Parse successful");
              fin.close();
          }
          catch(FileNotFoundException e)
          {
              System.out.println("File " + infile.getAbsolutePath() +
                      " could not be found on filesystem");
          }
          catch(IOException ioe)
          {
              System.out.println("Exception while reading the file" + ioe);
          }
          catch (Exception e) {
            /* do cleanup here -- possibly rethrow e */
          } finally {
    	/* do close out here */
          }
      }
    }

    The code compiles fine but the error message is received when the code is run.
    The errors are:
    Exception in thread "main" java.lang.NoClassDefFoundError: myparser/Yylex (wrong name: Yylex)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at myparser.Main.main(Main.java:27)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Main class Error

    Exception in thread "main" java.lang.NoClassDefFoundError: myparser/Yylex (wrong name: Yylex)
    The Yylex class is in a package. The code asked for it without the package name.

    Not sure how this error happened. Were there older versions that were not in the pacakge?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Main class Error

    No Sir there weren't any older versions in that package...

    --- Update ---

    But there is file denoted as Yylex.class that was generated in a different folder,I included them but still results in the same error.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Main class Error

    What is the classpath when the class is executed? What folder is the Yylex.class file in? Is the Yylex class in a package?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Error: Could not find or load main class
    By lijepdan in forum Java Theory & Questions
    Replies: 8
    Last Post: March 22nd, 2013, 04:32 PM
  2. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  3. Execution of .jar file: Could not find main class....Error'
    By suyog53 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2012, 02:04 PM
  4. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  5. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 11:40 PM