Sign in to follow this  

Please Help with Compiling Java!!!

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, This is so weird... I installed JDK 5.0 on my home computer and then installed textpad. The program I am working with compiles fine on all other computers in my College but won't compile at home computer. here is part of my code: Instructor.java
public class Instructor
{
	private int instNum;
	private String instName;

    /* Default Constructor**/
	public Instructor ()
	{
		instNum = 0;
		instName= "Not Set";
    }

	/* Parameterized Constructor **/
	public Instructor (String instName, int instNum)
	{
		setInstructorNumber (instNum);
		setInstructorName (instName);
	}

    /* Sets Instructor's Number **/
    public void setInstructorNumber (int instNum)
    {
		this.instNum = instNum;
	}

	/* Sets Instructor's Name **/
	public void setInstructorName (String instName)
	{
		this.instName = instName;
	}

	/* Gets Instructor Number **/
	public int getInstructorNum ()
	{
		return instNum;
	}

	/* Gets Instructor Name **/
	public String getInstructorName ()
	{
		return instName;
	}

	/* Gives a String representaion **/
	public String toString()
	{
		return "\t" + instName;
	}
}


Course.java
public class Course
{
	private String courseNum;
	private String courseName;
	private int credits;
	private int capacity;
	private int enrolled;
	private Instructor instructor;

    /* Default Constructor**/
	public Course ()
	{
		courseNum = "Not Set";
		courseName = "Not Set";
		credits = 0;
		capacity = 0;
		enrolled = 0;
		instructor = null;
	}

	/* Parameterized Constructor **/
	public Course (String courseNum, String courseName, int credits,
					int capacity, int enrolled, Instructor instructor)
	{
		setCourseNumber (courseNum);
		setCourseName (courseName);
		setCourseCredits (credits);
		setCapacity (capacity);
		setEnrolled (enrolled);
		this.instructor = instructor;
	}

	/* Sets Course Number **/
	public void setCourseNumber (String courseNum)
	{
		this.courseNum = courseNum;
	}

	/* Sets Course Name **/
	public void setCourseName (String courseName)
	{
		this.courseName = courseName;
	}

	/* Sets Course Credits **/
	public void setCourseCredits (int credits)
	{
		this.credits = credits;
	}

	/* Sets Seats Available **/
	public void setCapacity (int capacity)
	{
		this.capacity = capacity;
	}

	/* Sets Students Enrolled **/
	public void setEnrolled (int enrolled)
	{
		this.enrolled = enrolled;
	}

	/* Gets Course Number **/
	public String getCourseNumber()
	{
		return courseNum;
	}

	/* Gets Course Name **/
	public String getCourseName()
	{
		return courseName;
	}

	/* Gets Credits **/
	public int getCredits()
	{
		return credits;
	}

	/* Gets Course Capacity **/
	public int getCapacity()
	{
		return capacity;
	}

	/* Gets Students Enrolled **/
	public int getEnrolled()
	{
		return enrolled;
	}

	/* Gets Instructor **/
	public Instructor getInstructor()
	{
		return instructor;
	}

	/* Gives a String representation **/
	public String toString()
	{
		return "\t" + courseNum + "\t   " + credits;
	}
}


The Instructor.java compiles fine (and actually gives sensible errors when i put wrong code) but when I try to complile Course.java, i get following errors: -------------------------------------------------------------------------------- C:\Documents and Settings\Raj\Desktop\Test\Course.java:13: cannot find symbol symbol : class Instructor location: class Course private Instructor instructor; ^ C:\Documents and Settings\Raj\Desktop\Test\Course.java:28: cannot find symbol symbol : class Instructor location: class Course int capacity, int enrolled, Instructor instructor) ^ C:\Documents and Settings\Raj\Desktop\Test\Course.java:99: cannot find symbol symbol : class Instructor location: class Course public Instructor getInstructor() ^ 3 errors Tool completed with exit code 1 -------------------------------------------------------------------------------- And yes I do have both the files in the same folder. Please help! Thank you [Edited by - snm04 on January 26, 2006 8:11:57 PM]

Share this post


Link to post
Share on other sites
But are the compiled .class files in the same folder?

If thats not the problem, I'm not too sure then, but you might wanna look into an IDE like JBuilder (they have a free learning edition) to keep everything organized etc.

Java (From my experiance) also seems to have random package issues when compiling from the command line so its another reason to switch to an IDE.

If all else fails, a last thing you could try is declare them both in the same package and try again.

Share this post


Link to post
Share on other sites
Yes, everything is in the same folder (.class files and .java files). I even tried uninstalling both JDK and textpad and installed them back but no luck.

What do you mean by "declare them in same package"?

Share this post


Link to post
Share on other sites
If you are using Windows XP, go to start, then settings, then control panel, then system, then advanced, then click on environment variables, and search for a variable named CLASSPATH. If one doesn't exist, create a new one and type in something like .;c:\java\lib\ , if it does exist, edit it to search in the current directory by typing a period. The pathnames are separated by a semicolon. So .;c:\stuff;c:\things tells the JRE to search in three directories, one named c:\stuff, one named c:\things, and the current directory that you run javac and java.exe from.

Share this post


Link to post
Share on other sites
theres plenty of free ides out there for you to choose from. Netbeans was kinda slow with the "intellisense" when I tried it a long ways back. But that problem's been probably fixed by now.

As for the package, just add

package packageName;

to both classes. However compiling them might be a bit different. You may or may not have to add a "whatever.packageName.classname" instead now. I'm not too sure on this part but someone else may help you out...

Share this post


Link to post
Share on other sites
If you decide to use a package other than the default package (which you get from omitting the package keyword from your files), then the files must be in a directory of the same name as the package, and you must run from the parent folder to the one the files are in, by going like this:

java packageName.Mainclass

Share this post


Link to post
Share on other sites
Quote:
I seriously recomend netbeans.


In my experience, large scale projects with netbeans is horrible. On my PC is it not uncommon for it to be using 200-300+MB of ram, which kills my work computer with only 512. For large projects, I find that Visual Studio .NET as an IDE works very nicely. For a compiler, I just use build scripts.

~guyaton

Share this post


Link to post
Share on other sites

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this