July 26th, 2013, 12:24 AM
[SOLVED] Basic java question on package not found error
In my root folder (not drive root) , I have this file:
In this folder I also have a folder called media, in which I have the following two files:
// filename: Converter.java
// import media.*;
public class Converter
public static void main(String args)
if (args.length != 2)
System.err.println("usage: java Converter srcfile dstfile");
catch (InvalidMediaFormatException imfe)
System.out.println("Unable to convert " + args + " to " + args);
System.out.println("Expecting " + args + " to conform to " +
imfe.getExpectedFormat() + " format.");
System.out.println("However, " + args + " conformed to " +
imfe.getExistingFormat() + " format.");
catch (FileNotFoundException fnfe)
catch (IOException ioe)
// filename: InvalidMediaFormatException .java
public class InvalidMediaFormatException extends Exception
private String expectedFormat;
private String existingFormat;
public InvalidMediaFormatException(String expectedFormat,
super("Expected format: " + expectedFormat + ", Existing format: " +
this.expectedFormat = expectedFormat;
this.existingFormat = existingFormat;
public String getExpectedFormat()
public String getExistingFormat()
But at the root folder, if I do
public final class Media
public static void convert(String srcName, String dstName)
throws InvalidMediaFormatException, IOException
if (srcName == null)
throw new NullPointerException(srcName + " is null");
if (dstName == null)
throw new NullPointerException(dstName + " is null");
// Code to access source file and verify that its format matches the
// format implied by its file extension.
// Assume that the source file's extension is RM (for Real Media) and
// that the file's internal signature suggests that its format is
// Microsoft WAVE.
String expectedFormat = "RM";
String existingFormat = "WAVE";
throw new InvalidMediaFormatException(expectedFormat, existingFormat);
it keeps on giving me the error
. Why is this error still coming?
package media does not exist
Last edited by mahaju; July 26th, 2013 at 12:38 AM.
August 3rd, 2013, 10:23 AM
specifying classpath during compilation
Refer to the materials or user guide provided by Oracle Java site, you should specify the classpath of your application by providing the switch -classpath when you issue the command javac against your application during compilation.
There are actually many ways to compile an application. Depending on which way you compile your application, you should always specify the classpath whenever you issue javac command. In case you have set the CLASSPATH environment variable, or you are issuing the javac command at the classpath of your application itself, then it may not be necessary to specify the classpath explicitly. However, it is always the best practice to specify it using the -classpath switch of javac.
When the programming world turns decent, the real world will turn upside down.
August 3rd, 2013, 11:38 AM
Be sure to include a . in the CLASSPATH variable to include the current diredtory.