Solved

Java Package Classes Cannot Find Symbol

Posted on 2010-11-29
5
749 Views
Last Modified: 2012-05-10
Hi,
I am creating a Java program in a package called jblog. This consists of the main class BlogServer which needs to create objects of other classes in the same package.

I have stored all the Java source files for my package in a <path to source directory>/jblog
and am compiling these to the directory <path to classes directory>/jblog

When I attempt to compile the main java class - BlogServer I get Symbol Not Found errors for some of the other classes in my directory, the BlogServerInterface class (as well as other classes):

# javac -d ../../classes/jblog/ BlogServer.java
BlogServer.java:9: cannot find symbol
symbol: class BlogServerInterface
public class BlogServer implements BlogServerInterface

Both my BlogServer class and BlogServerInterface class are in the same jblog/ directory and have the package jblog line on the first line of the source file. Why can't the compiler find the BlogServerInterface class?

Thanks.

0
Comment
Question by:SnowCrash89
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34235697
you need to specify the classpath

javac -d ../../classes/jblog/ -classpath ../../classes BlogServer.java
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 34235699
that may actually be:


javac -d ../../classes/jblog/ -classpath ../../classes/blog BlogServer.java

its unclear if you are using packages or not
0
 

Author Comment

by:SnowCrash89
ID: 34235766
Ah, that worked, so when you're specifying a package name in your java files you have to use the -classpath parameter when compiling?
0
 
LVL 92

Expert Comment

by:objects
ID: 34235820
no, you need to specify the classpath if it needs to find dependant classes
the classpath is used to lookup classes
0
 

Author Comment

by:SnowCrash89
ID: 34235844
That's strange though, I've managed to compile succesfully a class with dependant classes without having to specify the classpath. Anyway problem solved.
Thanks.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 92
ArrayIndexOutOfBoundException 9 84
Java Jpanels and Jframe 8 33
eclipse argument 14 61
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question