• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Some Java help needed

markjrubin

Golden Member
I'm having a kooky problem compiling a very simple class and driver class. I have two classes, ShareYourThings.java and DVD.java. DVD.java is part of the package com.markjrubin.syt. When compiling ShareYourThings.java, not DVD.java , I get the error:

C:\java\syt>javac ShareYourThings.java
ShareYourThings.java:4: package com.markjrubin.syt does not exist
import com.markjrubin.syt.*;

I then get errors when trying to create new DVD objects. I have included the source for both file below.
---------------------
// ShareYourThings.java

import java.util.*;
import com.markjrubin.syt.*;

public class ShareYourThings {

static void prt (String s) {
System.out.println(s);
}

public static void main (String [] args)

{
DVD markjrubin1 = new DVD("markjrubin","Fleetwood Mac: The Dance"," "," ",1,20.99,false,false);
DVD farbio2 = new DVD("farbio","Any Given Sunday"," "," ",2,29.99,false,false);
DVD markjrubin3 = new DVD("markjrubin","American Beauty","Academy Award Winner"," ",3,20.99,false,false);

}

}

--------------------

-------------------
// DVD.java
package com.markjrubin.syt;

import java.util.*;
import java.text.*;

public class DVD {

protected String Username,Title,Comments,WhoHasItNow;
protected int DVDID;
protected double Value;
protected boolean isAvailable, isPrivate;

public DVD(String U, String T, String C, String W, int D, double V, boolean iA, boolean iP) {

Username = U;
Title = T;
Comments = C;
WhoHasItNow = W;
DVDID = D;
Value = V;
isAvailable = iA;
isPrivate = iP;
System.out.println("User: " + U + " has added a new DVD&quot😉;
}

public void printPrice()
{
NumberFormat nf;
nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
System.out.print("Value:$" + nf.format(Value));
}

public String getTitle()
{
return Title;
}
}

-------------------

Any help would be appreciated. I'm sure I'm just doing something stupid.
 
When you're using packages, things have to be placed in the proper directory after compilation, else you won't be able to access your superclass stuff. Should be something like c:\jdk1.3.0_02\jre\classes\com\markjrubin\syt\ in your case. When compiling you need to point the compiler to this directory.

I remember running into that problem with packages before. It's quite picky about the directory structure.

Hope that helps!
 
I have no classes directory in my jre folder under c:\jdk1.3.1

For more details, the DVD.java file compiles fine. It's only the ShareYourThings.java file that isn't happy.

Mark
 
OK - here are some questions/things to check

1. Are the 2 java files in the same directory? In this case since DVD.java has a
package declared and ShareYourThings.java does not - there can be an issue of



ShareYourThings.java

DVD.java
 
OK - I screwed up my post - let's try it one more time

Are the 2 java files in the same directory? If so this could be your problem.
To temporarily fix it you can take the package line out of DVD.java and if
they are both in the same directory they will compile.

If you want to keep the package line in then wherever the java files are you need
to create a directory called com/markjrubin/syt and move DVD.java there and then
from the base directory run the javac to compile "com/markjrubin/syt/DVD.java" and then
compile the other file.

You can have .java files from multiple packages in one source directory but when you
compile them - the .class files need to be in the right directory structure for the package layout. It can get really confusing. There are some command line options for javac to let you do this.

The best bet is to make your source tree directory structure match the package layout.

Hope this helps
 
Back
Top