futureminds
asked on
Compilation
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?
Thanks
futureminds
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?
Thanks
futureminds
ASKER
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?
futurem
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?
futurem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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){
eName=emName;
cName=compName;
rName=rlName;
}
public EmailUser(String fullAddress, String rlName){
eName=fullAddress;
cName="";
rName=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+"@"+s econdCompN ame, secondUsName);
EmailUser third = new EmailUser(firstName, firstCompName, firstUsName);
EmailUser fourth = new EmailUser(secondName+"@"+s econdCompN ame, secondUsName);
//Check emailName, computer and userName
if(first.emailName().equal s(firstNam e))
System.out.println("emailN ame OK1");
if(first.computer().equals (firstComp Name))
System.out.println("comput er OK2");
if(first.userName().equals (firstUsNa me))
System.out.println("userNa me OK3");
if(second.emailName().equa ls(secondN ame))
System.out.println("emailN ame OK4");
if(second.computer().equal s(secondCo mpName))
System.out.println("comput er OK5");
if(second.userName().equal s(secondUs Name))
System.out.println("userNa me OK6");
//Check the checkAddress method
if (EmailUser.checkAddress(se condName+" @"+secondC ompName))
System.out.println("checkA ddress OK7");
if (EmailUser.checkAddress(fi rstName+"@ "+firstCom pName))
System.out.println("checkA ddress OK8");
if (!EmailUser.checkAddress(f irstName+f irstCompNa me))
System.out.println("checkA ddress OK9");
if (!EmailUser.checkAddress(" @"+firstNa me+firstCo mpName))
System.out.println("checkA ddress OK10");
if (!EmailUser.checkAddress(f irstName+f irstCompNa me+"@"))
System.out.println("checkA ddress OK11");
//Check the equals method, also it is another test of the constructors
if(first.equals(third))Sys tem.out.pr intln("equ als OK12");
if(second.equals(fourth))S ystem.out. println("e quals OK13");
if(!first.equals(second))S ystem.out. println("e quals OK14");
if(!third.equals(fourth))S ystem.out. println("e quals 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
try
{
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?
Txs;
Futureminds.
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){
eName=emName;
cName=compName;
rName=rlName;
}
public EmailUser(String fullAddress, String rlName){
eName=fullAddress;
cName="";
rName=rlName;
}
static public boolean checkAddress(String fulladdress){
return fulladdress.indexOf("@")>=
}
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+"@"+s
EmailUser third = new EmailUser(firstName, firstCompName, firstUsName);
EmailUser fourth = new EmailUser(secondName+"@"+s
//Check emailName, computer and userName
if(first.emailName().equal
System.out.println("emailN
if(first.computer().equals
System.out.println("comput
if(first.userName().equals
System.out.println("userNa
if(second.emailName().equa
System.out.println("emailN
if(second.computer().equal
System.out.println("comput
if(second.userName().equal
System.out.println("userNa
//Check the checkAddress method
if (EmailUser.checkAddress(se
System.out.println("checkA
if (EmailUser.checkAddress(fi
System.out.println("checkA
if (!EmailUser.checkAddress(f
System.out.println("checkA
if (!EmailUser.checkAddress("
System.out.println("checkA
if (!EmailUser.checkAddress(f
System.out.println("checkA
//Check the equals method, also it is another test of the constructors
if(first.equals(third))Sys
if(second.equals(fourth))S
if(!first.equals(second))S
if(!third.equals(fourth))S
//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
try
{
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?
Txs;
Futureminds.
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.*
etc.
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.*
etc.
ASKER
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
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
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.
ASKER
Hi all;
I need to give the points to falter. He put a lot of effort into looking down the barrel for me.
txs
futurem
I need to give the points to falter. He put a lot of effort into looking down the barrel for me.
txs
futurem
ASKER
Thanks falter; thanks all.
futurem
futurem
Did you try compiling from the command line?