Go Premium for a chance to win a PS4. Enter to Win



Posted on 2000-05-17
Medium Priority
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 150 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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.io.*;
//import java.util.*;
import java.*;

class TestEmailUser

public static void main(String[] args)


String firstName = "d.c.ince";
String firstCompName = "talk21.com";
String firstUsName = "Darrel Ince";
String secondName = "S.J.Ince";
String secondCompName = "talk21.com";
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

import java.io.*


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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

971 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