Results 1 to 4 of 4
  1. #1
    jgro1976 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Question Newbie issue: Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJava

    Rest of error:
    Caused by: java.lang.classnotfoundexception: MyFirstJava
    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)
    Could not find the main class: myfirstjava. program will exit.

    Here's what I have:

    Environment variables:
    CLASSPATH=.
    Path=...;C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Program Files (x86)\Java\jdk1.7.0\lib;C:\Program Files (x86)\Java\jdk1.7.0\lib\tools.jar;C:\Program Files (x86)\Java\jdk1.7.0\lib\dt.jar;C:\Users\jgrover\Do cuments\Java

    Program installed at: c:\program files (x86)\java\jdk1.7.0
    My test files are at: C:\Users\jgrover\Documents\Java

    I saved my .java file as MyFirstJava.java, it compiled with no errors into the same folder as MyFirstJava.class, but when I try to run it, I get the above error message.

    I've tried futzing with the environment variables, but I can't get it to run. I'm new to this and trying to learn, but can't learn because I'm stuck, haha.

    Anyone see where my issue is?

    Thanks
    Jason

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

    Default Re: Newbie issue: Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJ

    Is there a MyFirstJava.class file in the directory where the java command was issued?
    If the classpath environment variable does NOT include a . for the current directory, you need to add one.
    Open a command prompt, go to the directory with the class file and enter a dir command to show the directories contents. Then enter:
    java -cp . MyFirstJava command.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    jgro1976 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Newbie issue: Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJ

    Here's a paste of the command you had me try (java -cp . myfirstjava), and a dir command of the file location.

    Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJava
    Caused by: java.lang.ClassNotFoundException: MyFirstJava
    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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\>java MyFirstJava
    Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJava
    Caused by: java.lang.ClassNotFoundException: MyFirstJava
    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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\>cd users\jgrover\documents\java

    c:\Users\jgrover\Documents\Java>javac MyFirstJava.java

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>c:\users\jgrover\d ocuments\java>set classpath=%c
    lasspath%;.;
    'c:\users\jgrover\documents\java' is not recognized as an internal or external c
    ommand,
    operable program or batch file.

    c:\Users\jgrover\Documents\Java>set classpath=%classpath%;.;

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>cd c:\

    c:\>cd program files

    c:\Program Files>dir
    Volume in drive C is Windows
    Volume Serial Number is 605C-6CF6

    Directory of c:\Program Files

    09/20/2011 10:00 AM <DIR> .
    09/20/2011 10:00 AM <DIR> ..
    03/03/2011 07:45 PM <DIR> Broadcom Corporation
    08/24/2011 11:25 AM <DIR> Common Files
    04/15/2011 03:06 PM <DIR> DellTPad
    03/03/2011 07:45 PM <DIR> DIFX
    03/01/2011 06:08 PM <DIR> DVD Maker
    03/03/2011 08:22 PM <DIR> IDT
    08/24/2011 10:47 AM <DIR> Internet Explorer
    03/02/2011 10:51 AM <DIR> Java
    08/24/2011 11:21 AM <DIR> Microsoft Analysis Services
    08/24/2011 04:46 PM <DIR> Microsoft IntelliPoint
    09/20/2011 10:00 AM <DIR> Microsoft IntelliType Pro
    08/24/2011 11:23 AM <DIR> Microsoft Office
    08/03/2011 09:47 AM <DIR> Microsoft Security Client
    08/24/2011 11:23 AM <DIR> Microsoft SQL Server Compact Edition
    08/24/2011 11:23 AM <DIR> Microsoft Sync Framework
    08/24/2011 11:24 AM <DIR> Microsoft Synchronization Services
    07/13/2009 10:32 PM <DIR> MSBuild
    03/03/2011 07:18 PM <DIR> NVIDIA Corporation
    07/13/2009 10:32 PM <DIR> Reference Assemblies
    03/01/2011 06:08 PM <DIR> Windows Defender
    03/01/2011 06:08 PM <DIR> Windows Journal
    05/24/2011 10:36 AM <DIR> Windows Live
    03/01/2011 06:08 PM <DIR> Windows Mail
    03/01/2011 06:08 PM <DIR> Windows Media Player
    07/13/2009 10:32 PM <DIR> Windows NT
    03/01/2011 06:08 PM <DIR> Windows Photo Viewer
    03/01/2011 06:08 PM <DIR> Windows Portable Devices
    03/01/2011 06:08 PM <DIR> Windows Sidebar
    0 File(s) 0 bytes
    30 Dir(s) 36,765,085,696 bytes free

    c:\Program Files>cd c:\

    c:\>dir
    Volume in drive C is Windows
    Volume Serial Number is 605C-6CF6

    Directory of c:\

    12/01/2006 11:37 PM 904,704 msdia80.dll
    07/13/2009 08:20 PM <DIR> PerfLogs
    09/20/2011 10:00 AM <DIR> Program Files
    09/09/2011 09:05 PM <DIR> Program Files (x86)
    05/13/2011 12:15 PM <DIR> Users
    09/21/2011 09:49 AM <DIR> Windows
    1 File(s) 904,704 bytes
    5 Dir(s) 36,765,609,984 bytes free

    c:\>program files (x86)
    'program' is not recognized as an internal or external command,
    operable program or batch file.

    c:\>cd program files (x86)

    c:\Program Files (x86)>java MyFirstJava
    Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJava
    Caused by: java.lang.ClassNotFoundException: MyFirstJava
    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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Program Files (x86)>cd c:\users\jgrover\documents

    c:\Users\jgrover\Documents>dir
    Volume in drive C is Windows
    Volume Serial Number is 605C-6CF6

    Directory of c:\Users\jgrover\Documents

    09/26/2011 09:55 AM <DIR> .
    09/26/2011 09:55 AM <DIR> ..
    09/26/2011 11:36 AM <DIR> Java
    05/23/2011 02:39 PM 11,877 Lista Domini per VI.xlsx
    09/25/2011 08:05 PM <DIR> My Kindle Content
    05/24/2011 10:43 AM <DIR> My Received Files
    04/25/2011 12:42 PM 12,343 New Workspace Set Up.docx
    09/27/2011 02:17 PM <DIR> Outlook Files
    09/26/2011 07:00 PM <DIR> VI - QA
    09/27/2011 01:39 AM <DIR> VI - Test Drive Report
    08/22/2011 09:46 AM <DIR> VT
    05/25/2011 11:23 AM 69,462 VT Expense Report 5-30.xlsx
    3 File(s) 93,682 bytes
    9 Dir(s) 36,690,251,776 bytes free

    c:\Users\jgrover\Documents>cd java

    c:\Users\jgrover\Documents\Java>dir
    Volume in drive C is Windows
    Volume Serial Number is 605C-6CF6

    Directory of c:\Users\jgrover\Documents\Java

    09/26/2011 11:36 AM <DIR> .
    09/26/2011 11:36 AM <DIR> ..
    09/26/2011 10:58 AM 427 MyFirstJava.class
    09/26/2011 10:57 AM 106 MyFirstJava.java
    09/26/2011 11:36 AM 0 set
    3 File(s) 533 bytes
    2 Dir(s) 36,690,251,776 bytes free

    c:\Users\jgrover\Documents\Java>java -cp . MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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)
    Could not find the main class: MyFirstJava. Program will exit.

    c:\Users\jgrover\Documents\Java>dir
    Volume in drive C is Windows
    Volume Serial Number is 605C-6CF6

    Directory of c:\Users\jgrover\Documents\Java

    09/26/2011 11:36 AM <DIR> .
    09/26/2011 11:36 AM <DIR> ..
    09/26/2011 10:58 AM 427 MyFirstJava.class
    09/26/2011 10:57 AM 106 MyFirstJava.java
    09/26/2011 11:36 AM 0 set
    3 File(s) 533 bytes
    2 Dir(s) 36,687,646,720 bytes free

    c:\Users\jgrover\Documents\Java>

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

    Default Re: Newbie issue: Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstJ

    c:\Users\jgrover\Documents\Java>java MyFirstJava
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstJava :
    Unsupported major.minor version 51.0
    This one looks like the java command was reading the MyFirstJava.class file and found that the version of java that created it was younger than the java.exe file.
    Are there different versions of java on your machine?
    It looks like the javac.exe program you used is version 1.7.
    What version is the java.exe program?
    Enter:
    java -version
    to get the version information

Similar Threads

  1. Replies: 5
    Last Post: 04-27-2011, 02:13 AM
  2. Replies: 5
    Last Post: 06-02-2010, 01:05 PM
  3. Replies: 3
    Last Post: 06-01-2010, 03:01 PM
  4. Replies: 1
    Last Post: 04-02-2009, 09:50 PM
  5. Replies: 6
    Last Post: 08-18-2008, 06:44 AM

Tags for this Thread

Posting Permissions

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