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

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?

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails


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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now