• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java compile trouble

 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, i am a newbie in java. While compiling this code(which i wrote to test whether swing's JFrame was working or not so as to add more components) I encountered an error:

Here's the code:
Test class code


MarkAnalysis class code


The error message was :

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Mohan>javac Test.java
Test.java:5: cannot find symbol
symbol : class MarkAnalysis
location: class Test
MarkAnalysis marks = new MarkAnalysis() ;
^
Test.java:5: cannot find symbol
symbol : class MarkAnalysis
location: class Test
MarkAnalysis marks = new MarkAnalysis() ;
^
2 errors

C:\Documents and Settings\Mohan>


Please help me. I am using Windows XP.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling both in one go: "javac *.java". That will compile all Java files in the current directory.
 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your Test class should import MarkAnalysis class.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And maybe add a package to both classes.....
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is definitely a classpath issue.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50173
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhakar Bokka wrote:This is definitely a classpath issue.
How do you know? It might not be.

Are both those classes in the same folder? What happens when you write "javac MarkAnalysis.java"? And you cannot import a class without a package name, but forget all about package names and imports at this stage.
 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The files are in the same folder. I have tried this before while i was coding a calculator program. There was no problem then. The only change I made was install the newer version of java sdk.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a dot (.) in your classpath??
 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Try compiling both in one go: "javac *.java". That will compile all Java files in the current directory.


It worked: i compiled it together

But the trouble is at execution time now----



C:\Documents and Settings\Mohan>java Test.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test/class
Caused by: java.lang.ClassNotFoundException: Test.class
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: Test.class. Program will exit.

C:\Documents and Settings\Mohan>
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then its current directory classpath issue.

Set class path to the currnet directory.


Do you have a dot (.) in your classpath??



set classpath=.;c:\...\jdk\lib;
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't use .class extension when running a class file. Use "Java Test" instead.
 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys!!! I made a very very silly mistake!!!

The part i went wrong in was executing it as :

java Test.class


The .class part was not necessary. I just had to write java Test, and voila I got an 800*600 window!

Thanks a lot...You guys gave me the best help. I'll keep troubling you guys though, cause i am still a novice.

Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic