This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Using sublime to code Java class. How to import another class file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

New to Java.

I have written a class named School with few attributes and 2 simple methods. This java file compiled successfully.

I want to instantiate object of this School in another class called SchoolApp which has Main method. I am using sublime as text editor.

How to import or refer the School class file in my SchoolApp file?

Here is the code of SchoolApp file:



When I compile SchoolApp (javac SchoolApp.java), I am getting the following error:

SchoolApp.java: error: cannot find symbol
School aschool = new School();

I am sure I don't know how to reference School class in my SchoolApp.java file. Any suggestions how to fix this.

Thank you very much
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jasonsmith nath wrote:I have written a class named School with few attributes and 2 simple methods. This java file compiled successfully.



And what package is it in? If you put it in the School package then you shouldn't have to import it into SchoolApp, so it appears you didn't put it there. If you didn't put it into any package then you won't be able to import it into SchoolApp, so if that's what you did then you're going to have to put it into some package.

To me it seems like it ought to be in the School package too, so why don't you try putting it there? No import would be necessary then.

Also... it's standard for package names to start with lower-case letters, e.g. "school". Right now your "School" package can be confused with your "School" class by people reading your code.
 
I'm still in control here. LOOK at this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!