Posted on 2000-05-17
Last Modified: 2013-11-23
I wrote a very simple class and comiled it OK. Another class was provided to me by someone else, the idea being that their class tests mine.

But I cannot compile the class that was given to me. I get error messages saying that "Class blah-blah cannot be found in Type Definition". Searching the IDE help I see that such an error message is produced when a typo has been made or the package cant be found. I made a package (which I dont think I really need anyway) and checked my typing, but still no luck. Has anyone got the foggiest where I am going wrong with this?

Question by:futureminds

Expert Comment

ID: 2819136
What are the two classes (their names and package names)? And where did you place the two relative to your CLASSPATH (if you have one defined).

Did you try compiling from the command line?

Author Comment

ID: 2819386
One class is called EmailUser (the one I wrote) and the other is called TestEmailUser (which I was provided with). They dont really have package names, but when I tried putting a package name in each class it didnt make any difference.

Mine was written with the JDK v 1.1 and the other was provided to me as a textfile. The compilation was done from the command line. As for the CLASSPATH, is that the same as the PATH?


Accepted Solution

falter earned 50 total points
ID: 2819478
CLASSPATH is not the same as PATH!
PATH determines where your OS will lok for executables, if you specify them without the full path.
CLASSPATH tells the JVM where to llok for classes needed at Compile/Runtime

Can you post source code?

It will help to find an answer
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 2820645
Hi falter:

This is the code for the class that I wrote, called EmailUser, which compiles OK:

public class EmailUser{

private String eName, cName,rName;

public EmailUser(String emName, String compName, String rlName){



public EmailUser(String fullAddress, String rlName){



static public boolean checkAddress(String fulladdress){

return fulladdress.indexOf("@")>=0 && !fulladdress.startsWith("@") && !fulladdress.endsWith("@");


public String emailName(){

return eName;


public String computer(){

return cName;


public String userName(){

return rName;


public boolean equals(EmailUser EmUser){

return this.equals(EmUser);


and this is the class that was supplied to me which when I try compiling returns error saying that Class EmailUser cannot be found in type declaration:

//import java.util.*;
import java.*;

class TestEmailUser

public static void main(String[] args)


String firstName = "d.c.ince";
String firstCompName = "";
String firstUsName = "Darrel Ince";
String secondName = "S.J.Ince";
String secondCompName = "";
String secondUsName = "Steph Ince";

//EmailUser first, second, third, fourth;

EmailUser first = new EmailUser(firstName, firstCompName, firstUsName);
EmailUser second = new EmailUser(secondName+"@"+secondCompName, secondUsName);
EmailUser third = new EmailUser(firstName, firstCompName, firstUsName);
EmailUser fourth = new EmailUser(secondName+"@"+secondCompName, secondUsName);

//Check emailName, computer and userName

  System.out.println("emailName OK1");
  System.out.println("computer OK2");
  System.out.println("userName OK3");
  System.out.println("emailName OK4");
  System.out.println("computer OK5");
  System.out.println("userName OK6");

//Check the checkAddress method

if (EmailUser.checkAddress(secondName+"@"+secondCompName))
  System.out.println("checkAddress OK7");
if (EmailUser.checkAddress(firstName+"@"+firstCompName))
  System.out.println("checkAddress OK8");
if (!EmailUser.checkAddress(firstName+firstCompName))
  System.out.println("checkAddress OK9");
if (!EmailUser.checkAddress("@"+firstName+firstCompName))
  System.out.println("checkAddress OK10");
if (!EmailUser.checkAddress(firstName+firstCompName+"@"))
  System.out.println("checkAddress OK11");

//Check the equals method, also it is another test of the constructors

if(first.equals(third))System.out.println("equals OK12");
if(second.equals(fourth))System.out.println("equals OK13");
if(!first.equals(second))System.out.println("equals OK14");
if(!third.equals(fourth))System.out.println("equals OK15");

//The code makes sure that your MSDOS window
//stays put for 10 seconds
//so you can examine your results. Don't worry about
//it yet it appears in the middle of the course

  Thread.sleep(10000); // Displays MSDOS window for 10 seconds
catch(Exception e){}


I see what you mean about CLASSPATH, but my classpath in Autoexec.bat doesnt refer to the directory where the classes are stored. Does that affect anything do you think?


Expert Comment

ID: 2821192
For your simple case, place both files in the same directory, open the command window, change to that directory and try

javac -classpath . *.java

Make sure the .class files are created for both clases. Then

java -classpath . TestEmailUser

That should work.

By the way, the statement

import java.*;

is an invalid one (unless you are importing all classes in package "java" which is unlikely).

You should have



Author Comment

ID: 2822031
I looked at autoexec.bat file and found that my new Adobe graphics software had added a line that goes "@SET CLASSPATH ... ".

This made me suspicious and then I remembered that I had previously been able to both compile and run two other simple classes a couple of weeks ago before I installed the new Adobe software. I have no idea why it needed to make that adjustment to autoexec, so I remmed it out, rebooted, and hey presto, it worked. I left everything else as it had been, and so I didnt really need to make use of the solutions posted here. Let me know what you want to do about this.
Txs; Futureminds

Expert Comment

ID: 2828344
well what i can say the class which yr friend has provided u n yr class  r not in the package. SO what i can suggest u can put bothe the packages in the same package n then try to compile . I hope u can get the perfect result.


Author Comment

ID: 2828493
Hi all;

I need to give the points to falter. He put a lot of effort into looking down the barrel for me.



Author Comment

ID: 2828496
Thanks falter; thanks all.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

820 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