• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java compile trouble

 
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.
 
Rancher
Posts: 43016
76
  • 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.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your Test class should import MarkAnalysis class.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And maybe add a package to both classes.....
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is definitely a classpath issue.
 
Marshal
Posts: 70228
282
  • 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
Mac OS X Eclipse IDE
  • 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: 198
Oracle Spring Java
  • 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;
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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.
 
pie. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic