Dear All,
I have one main class calling another class but I keep getting this error "
SMSClient cannot be resolved to a type". Before this I tried on other pc it was ok. Below is part of the codes. What could have been wrong?

public class callSMSClient{

  public static void main(String[] args)
  {
  	SMSClient t1 = new SMSClient(0);
  	t1.sendMessage("+6065544223","testing one two");
  }
}
public class SMSClient implements Runnable{

  public final static int SYNCHRONOUS=0;
  public final static int ASYNCHRONOUS=1;
  private Thread myThread=null;

  private int mode=-1;
  private String recipient=null;
  private String message=null;

  public int status=-1;
  public long messageNo=-1;


  public SMSClient(int mode) {
      this.mode=mode;
    }

  public int sendMessage (String recipient, String message){
    this.recipient=recipient;
    this.message=message;
    //System.out.println("recipient: " + recipient + " message: " + message);
    myThread = new Thread(this);
    myThread.start();
//    run();
    return status;
    }
    public void run(){

    Sender aSender = new Sender(recipient,message);

    try{
      //send message
          aSender.send ();

         // System.out.println("sending ... ");

      //in SYNCHRONOUS mode wait for return : 0 for OK, -2 for timeout, -1 for other errors
      if (mode==SYNCHRONOUS) {
          while (aSender.status == -1){
            myThread.sleep (1000);
          }
      }
      if (aSender.status == 0) messageNo=aSender.messageNo ;

    }catch (Exception e){

        e.printStackTrace();

    }

    this.status=aSender.status ;

    aSender=null;


  }
}

Recommended Answers

All 16 Replies

You are missing a library.

Dear Masijade,
What library could be missing ya? Any idea please? Thank you.

Whatever library this "SMSClient" is a part of. I have no idea what library it comes from. All I can say is to search through the jars used on "your other PC" and or to try and find it with Google.

Dear Masijade,
I have closed all the codes but the basic call of the SMSClient from the other class also gives the same error. So what fundamental error could it be?

What I have already said. That you do not have the jar containing this SMSClient class on your classpath.

Dear Masijade,
I am not sure what is jar all about. But I have modified my codes to something below yet I get the same errors. I am using linux environment so I type this command javac callSMSClient.

public class callSMSClient{

  public static void main(String[] args)
  {
  	SMSClient t1 = new SMSClient(1);
  	t1.sendMessage("+6014466044","testing one two");
  }
}
public class SMSClient {

  private int mode=-1;
  private String recipient=null;
  private String message=null;

 

  public SMSClient(int mode) {
      this.mode=mode;
    }

  public void sendMessage (String recipient, String message){
    this.recipient=recipient;
    this.message=message;
    System.out.println("recipient: " + recipient + " message: " + message);
 
    }
  
}

It has nothing to do with the code. You are missing a library.

Dear Masijade,
So is that my java installation have problem is it? How can I trace which library am I missing? I am using centos 5.5. Any help on that?

Nevermind. I see (now) that this SMSClient class is one you've copied off the web. Do you, personally, know anything about Java? Because now it looks as though the problem is simply that you have not given the classes packages and that you probably do not have cwd (i.e. . ) in your classpath. try "executing" with "-cp .".

Dear Masijade,
Yes I argee I copied from the net and trying to play around it to learn further. To be frank I am not any expert in java yes I know the basics though. So when you say the packages is the java comm package is it? That I have configured accordingly and I quite sure it works well because I have my own short code and it is able to send sms via that. The problem I am not good with packages. I dont get you when you say try executing with -cp. Did you mean java -cp callSMSClient.java?

No. I meant to give your classes a package. Any package. The first code line in your code should be "package whatever.package.name.you.want;" If you do not have that the classes are in the "default" (i.e. no package) package and there are problems including classes from that package (which the smaller class is attempting to do and is probably the reason for the "cannot be resolved". Now I really have a beef with schools (if that is where you are "learning"). They always have students start out in the "default" package and then, as soons as they try anything else, this sort of thing starts to happen and they have no clue what is happening (not to mention the fact that they have them using IDEs and so the students no nothing about the classpath, the second part of this problem), they should learn packages (at least this part of it) as one of the first things. As far as the classpath goes, also, no. I assume you have both of these classes in the same place? In that case

java -cp . callSMSClient

As I said, use "-cp . ".

Dear Masijade,
Yes you are the right guru I have added the statement package sms; in the first line of the both the codes and it works. The problem now when I compile I write like this javac sms/callSMSClient.java sms/SMSClient.java. So if your notice this there altogether 6 codes from the web. So I have added in each of it the package statement. How do I compile it now? Thank you.

Did you move the source files into a subdirectory of the current directory called sms? if not (and you do not necessarily, have to) then you do not need to use sms/SMSClient.java, but rather still, simply, SMSClient.java by compilation a sms subdirectory will be created (if it doesn't eixst, and the classfiles will be found there, and the execute command will then be

java -cp . sms.SMSClient

Dear Masijade,
Yes I have moved all into the a folder called sms. So what command must I run to compile all the files named as callSMSClient.java,SMSClient.java,Sender.java,SerialConnection.java,SerialParameters.java and SerialConnectionException.java.In each of the code at the top I have added the statement package sms.

javac -cp . sms/*.java

Dear Masijade,
Ok I would like to learn what is the -cp . is for? On the other hand I now tried both the codes with the package statement and without both is able to be compiled without any error? Can I know why this happens?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.