5 Replies - 4590 Views - Last Post: 11 November 2010 - 02:22 PM Rate Topic: -----

#1 Guest_grapher*


Reputation:

Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 12:37 AM

Hello DIC.

This is the example helloworld code that came with jgraph


//package com.mxgraph.examples.swing;

import javax.swing.JFrame;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

class HelloWorld extends JFrame
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2707712944901661771L;

	public HelloWorld()
	{
		super("Hello, World!");

		mxGraph graph = new mxGraph();
		Object parent = graph.getDefaultParent();

		graph.getModel().beginUpdate();
		try
		{
			Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
					30);
			Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
					80, 30);
			graph.insertEdge(parent, null, "Edge", v1, v2);
		}
		finally
		{
			graph.getModel().endUpdate();
		}

		mxGraphComponent graphComponent = new mxGraphComponent(graph);
		getContentPane().add(graphComponent);
	}

	public static void main(String[] args)
	{
		HelloWorld frame = new HelloWorld();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(400, 320);
		frame.setVisible(true);
	}

}




I compiled it using

javac -cp jgraphx.jar HelloWorld.java <<-- Compiled OK

but when i try to run

java -cp jgraphx.jar HelloWorld

i get a big error

java -cp jgraphx.jar HelloWorld

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
        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: HelloWorld.  Program will exit.



please help me!

Is This A Good Question/Topic? 0

Replies To: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

#2 MrLuke187  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 81
  • View blog
  • Posts: 237
  • Joined: 09-July 10

Re: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 12:52 AM

There are easier ways to do this. But i think your Problem is the run-command. If you export a .jar File, your command should be:
java -jar [filename]


Greetings: Luke
Was This Post Helpful? 0
  • +
  • -

#3 Guest_tyt*


Reputation:

Re: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 04:27 AM

Are you mad #2 MrLuke187 ? I don't want to run the jgraphx.jar library file. Its a class path issue and i solved it.
Was This Post Helpful? -4

#4 Guest_Me*


Reputation:

Re: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 05:43 AM

How can i set the classpath of a jar file in ubuntu ?
Was This Post Helpful? 0

#5 MrLuke187  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 81
  • View blog
  • Posts: 237
  • Joined: 09-July 10

Re: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 11:18 AM

View PostMe, on 11 November 2010 - 12:43 PM, said:

How can i set the classpath of a jar file in ubuntu ?

You shouldn't do this by hand, use a good IDE like Eclipse, it will do it for you.

Greetings: Luke
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,991
  • Joined: 20-September 08

Re: Exception in thread "main" java.lang.NoClassDefFoundError: Hel

Posted 11 November 2010 - 02:22 PM

Quote

java -cp jgraphx.jar HelloWorld




should be

java -cp jgraphx.jar:. HelloWorld


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1