user2154283
user2154283

Reputation: 291

Java NoClassFoundDefError and ClassNotFoundException issue

I just spent two hours reading posts everywhere on the internet talking about this issue, but I haven't one that would have the solution I'm looking for.

I have created a Java application in Eclipse. I exported it as Jar File, Runnable Jar File (I tried all three options : extract required libraries, package required libraries...) and the Jar Files all run fine on my Windows 7 where I developed the application.

I tried using it on another computer I have, with Windows Vista. If I double click the jar file I get an error message saying "Could not find the main class : Golf_Calculator. Program will exit.". I tried running it with the command, and I get this :

C:\Users\Geoffroy\Desktop\Golf Calculator>java Golf_Calculator.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Golf_Calculator/jar
Caused by: java.lang.ClassNotFoundException: Golf_Calculator.jar
    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: Golf_Calculator.jar.  Program will exit.

I really don't know what to do.. My META-INF folder is in the Jar File and contains the MANIFEST.MF file with the correct Main Class name. I read that may be it could come from the fact that the classes I import in my code are not in the main directory, but when generating the Runnable Jar File with Eclipse, using the "extract required libraries" option, I thought it would fix the problem. Nope it didn't.. Here are all the imports I do in my code, may be that will give you a hint:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.Box.Filler;
import javax.swing.event.TableModelListener;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

I hope that someone out there will be able to help me :)

Thanks a lot!

EDIT : I tried this : java -jar Golf_Calculator.jar and got this :

C:\Users\Geoffroy\Desktop\Golf Calculator>java -jar Golf_Calculator.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: Golf_Calculat
or : 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(Unknown 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: Golf_Calculator. Program will exit.

Upvotes: 2

Views: 935

Answers (2)

Jeevan Patil
Jeevan Patil

Reputation: 6079

You are not running a java file, it's a jar file. Run it using following command.

java -jar Golf_Calculator.jar

Upvotes: 3

hd1
hd1

Reputation: 34677

You need to run it as java -jar Golf_Calculator.jar

Upvotes: 1

Related Questions