• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Java files not seeing one another?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created 2 files: Sphere.java and CreateSpheres.java files -- in the same directory.
Sphere.java is 'stand-alone' and compiled fine.
CreateSpheres.java references 'Sphere' objects, and does NOT compile. An error message occurs on every line where 'Sphere' is referenced.
For example:
CreateSpheres.java:7: cannot resolve symbol
symbol : class Sphere
location: class CreateSpheres
Sphere ball = new Sphere(4, 0, 0, 0);
^
Why is this happening? Do I need an import statement? Do I need to use 'extends Sphere' in the 2nd program? Or something else?
I'm a REAL beginner, so please go easy on me and use small words.
Thank you!
Susan

[This message has been edited by Susan Delph (edited April 10, 2001).]
[This message has been edited by Susan Delph (edited April 10, 2001).]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you do not have a package statement in any of your files. You may also want to use the public keyword infront of your class declaration.
Bosun
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it sounds like you don't need any import statements and
you don't need to have anything extends anything.
could you post your code for us? just make sure to put
the code inside [ C O D E ] and [ / C O D E ] delimiters
(without the spaces i put in so it would show up right.)
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi susan,
if both your calsses are in the samae directory then they must recognise each other even if the specifier is friendly.
check that the spellings are right.or the constructor signature matches ,that is where we make mistakes.
do this keep all your files in the bin directory on a folder above that takes out all the headache of seting the calss path.
use an editor called JPadPro its the best i have come accross.
regards
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you might want to try :

Where file.java is your source file. Sometimes, for some reason, the class path gets screwed up and doesn't include the current directory. ( I haven't had this problem on stand-alone systems, but at work I had to do this before I explicitly added the current directory ( . ) to my classpath. )
HTH,
-Nate
 
Susan Delph
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Nate!
javac -classpath . file.java
did the trick!
It's strange: the stand-alone program compiled fine without the classpath, but the other (which references the first) needed that classpath . specified.
It's working, and running, just fine now!
Thanks again!
Susan
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Susan,
I was playing with the Shapes classes in the Code Barn and had the same problem. In my case, it was because I had not compiled the Shape.java, Circle.java, Box.java and Poly.java files. As soon as I compiled them and then tried running the ShowShapes.java file again it worked fine.
 
sanjays samadder
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it also works if you put all your files in the bin directory
or a directory above
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic