aspose file tools*
The moose likes Beginning Java and the fly likes java compile trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java compile trouble" Watch "java compile trouble" New topic
Author

java compile trouble

Hari Mohanan
Greenhorn

Joined: Jun 30, 2010
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 42644
    
  65
Try compiling both in one go: "javac *.java". That will compile all Java files in the current directory.


Ping & DNS - my free Android networking tools app
nimish kumar
Ranch Hand

Joined: Dec 04, 2009
Posts: 56
your Test class should import MarkAnalysis class.


IBM-IBM WebSphere Application Server Network Deployment V7.0, Core Administration.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

And maybe add a package to both classes.....


Regards, Rene Larsen
Dropbox Invite
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

This is definitely a classpath issue.


SCJP 5, SCWCD 5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
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

Joined: Jun 30, 2010
Posts: 8
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

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Jun 30, 2010
Posts: 8
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

Joined: Jul 26, 2005
Posts: 193

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

Joined: Mar 24, 2008
Posts: 3855

You don't use .class extension when running a class file. Use "Java Test" instead.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Hari Mohanan
Greenhorn

Joined: Jun 30, 2010
Posts: 8
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java compile trouble