Results 1 to 20 of 24
- 01-03-2013, 11:37 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
- 01-03-2013, 11:54 AM #2
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
You don't "run" a class file. There is usually one class with a public static void main method. That is the one you start using java MyMainClass. All the other class files are used by your main class and all the other classes that you instantiate. The classloader will take care of reading the .class files.
- 01-03-2013, 12:55 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
Well then i have problem with my main. it says Cannot find or load the main class.
code is located here. cannot find symbol. I fixed the cannot find smbol so thats not the problem anymore.
- 01-03-2013, 01:04 PM #4
Re: source code in multiple .class files
Why do they call it rush hour when nothing moves? - Robin Williams
- 01-03-2013, 01:05 PM #5
- 01-03-2013, 02:50 PM #6
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
[CODE]package donut;
import javax.swing.JFrame;
public class Donut extends JFrame {
public Donut() {
add(new Board());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(360, 310);
setLocationRelativeTo(null);
setTitle("Donut");
setVisible(true);
}
public static void main(String[] args) {
new Donut();
}
}[CODE]
As you can see i have the public static void main in here. And if i run this it sais cannot load or find mind .class
- 01-03-2013, 03:00 PM #7
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
The errors are constantly changing now im getting
Exception in thread "main" java.lang.NoClassDefFoundError: Donut (wrong name: do
nut/Donut)
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)
- 01-03-2013, 03:50 PM #8
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
Your code example runs fine here. What is the commandline you are using to start you main class?
- 01-03-2013, 04:29 PM #9
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
java Donut. My suspicion is that i havent gotten the JDK propely installed. i added the java folder in the PATH in the global variables. Anything else?
Last edited by vastrolorde; 01-03-2013 at 04:33 PM.
- 01-03-2013, 07:32 PM #10
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
You should add the packagename as well, so the proper command is java donut.Donut
- 01-03-2013, 11:04 PM #11
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
C:\Users\Marko\Desktop\java>java donut.Donut
Error: Could not find or load main class donut.Donut
- 01-04-2013, 07:36 AM #12
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
Unless you added C:\Users\Marko\Desktop\java to the CLASSPATH environment variable, java.exe will still not find the classes you are trying to feed it. Try java -cp . donut.Donut
-cp . tells java that it needs to find the classes in the current directory.
- 01-04-2013, 10:45 AM #13
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
C:\Users\Marko\Desktop\java>java -cp . donut.Donut
Error: Could not find or load main class donut.Donut
- 01-04-2013, 10:52 AM #14
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
Are the compiled classes in C:\Users\Marko\Desktop\java or are those only the source files? The command I gave you must be run from the directory where all the class files are.
- 01-04-2013, 11:26 AM #15
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
When i run the javac command it creates the .class files in the same folder. I think i might have installed JDK wrongly. I downloaded JDK6. I installed it and then i added the C:/program files .... JDK.... To the Path. Is there anything else i must do?
- 01-04-2013, 12:36 PM #16
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
Is the Donut class REALLY in the donut subdirectory? And do you run the java command from the root of your project, so from C:\Users\Marko\Desktop\java and not C:\Users\Marko\Desktop\java\donut?
- 01-04-2013, 12:47 PM #17
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
there is no subdirectory called donut. the java folder contains few things. a folder called new folder inside there is another .class file that i couldnt get running becaus of the same problem. other things are Board.java, Board.class and Donut.java , Donut.class
- 01-04-2013, 02:48 PM #18
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: source code in multiple .class files
In your code you wrote package donut;. That means it should be in a subdirectory donut. The Donut.java file needs to be in that directory. So it ends up here: C:\Users\Marko\Desktop\java\donut\Donut.java
- 01-04-2013, 03:21 PM #19
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: source code in multiple .class files
So i created a folder and named it donut. I placed Donut.java in it. But i still get the same error
- 01-04-2013, 03:32 PM #20
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Similar Threads
-
read source code from a class
By argus in forum New To JavaReplies: 6Last Post: 10-14-2010, 07:05 PM -
Project containing multiple source files
By mr smiley in forum EclipseReplies: 0Last Post: 04-25-2009, 10:31 PM -
How to Compile JavaScript source into Java class files
By tosreejith in forum New To JavaReplies: 0Last Post: 04-06-2009, 03:12 PM -
multiple class files
By nemesys571 in forum EclipseReplies: 0Last Post: 06-26-2008, 01:58 AM -
Organize class source code
By Alejandro Valdez in forum EclipseReplies: 0Last Post: 05-16-2008, 02:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks