Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cannot find symbol

843810Jul 31 2006
After compiling Port.java
I am getting following error
The class path are set

C:\Program Files\Java\jdk1.5.0\bin\javac.exe Port.java
Working Directory - C:\Program Files\Java\jdk1.5.0\smspack\
Class Path - .;c:\Kawa4.1\kawaclasses.zip;c:\program files\java\jdk1.5.0\lib\tools.jar;c:\program files\java\jdk1.5.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0\smspack;C:\Program Files\Java\jre1.5.0\lib\comm.jar
File Compiled...

--------------------------- Compiler Output ---------------------------
Port.java:34: cannot find symbol

symbol : variable SMS

location: class smspack.Port

CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(SMS.COMPORT);

^

Port.java:43: cannot find symbol

symbol : variable SMS

location: class smspack.Port

SMS.showText("could not open port:" + e);

^

Port.java:65: cannot find symbol

symbol : variable SMS

location: class smspack.Port

SMS.showText("ERROR: send AT command failed; " + "Command: " + atcommand + "; Answer: " + s + " " + e);

^

Port.java:143: cannot find symbol

symbol : variable SMS

location: class smspack.Port

SMS.showText("Error: close port failed: " + e);

^

4 errors

PORT.JAVA
package smspack;

import java.io.*;
import java.rmi.*;
import java.util.*;
import javax.comm.*;

class Port {
private static String portName;
private static SerialPort port;
private static OutputStreamWriter out;
private static InputStreamReader in;

private static String number;
private static String message;
private static boolean numbertype; // national or international dialing number

/** open the connection via the serial line
* @throws Exception
*/
public static void open() throws Exception {
//----- open the connection via the serial line
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(SMS.COMPORT);
port = (SerialPort)portId.open("SMS Transceiver", 10); // open port
// set parameter for serial port
port.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
out = new OutputStreamWriter(port.getOutputStream(), "ISO-8859-1");
in = new InputStreamReader(port.getInputStream(), "ISO-8859-1");
System.out.println("open port\n"); // for debugging
} // try
catch (Exception e) {
SMS.showText("could not open port:" + e);
System.exit(0);
} // catch
} // open


/** sends an AT command to ME and receives the answer of the ME
* @param atcommand AT command for the GSM Modem
* @return answer string of the ME
* @throws java.rmi.RemoteException
*/
public static String sendAT(String atcommand) throws java.rmi.RemoteException {
String s="";

try {
Thread.sleep(300); // wait 300 msec [Timing]
writeln(atcommand); // send AT command to ME
Thread.sleep(300); // wait 300 msec [Timing]
s = read(); // get response from ME
Thread.sleep(300); // wait 300 msec [Timing]
} // try
catch (Exception e) {
SMS.showText("ERROR: send AT command failed; " + "Command: " + atcommand + "; Answer: " + s + " " + e);
} // catch
return s;
} // sendAT

/** write a string to the output buffer
* @param s string for the serial output buffer
* @throws Exception
*/
public static void write(String s) throws Exception {
out.write(s);
out.flush();
} // write

/** write a character to the output buffer
* @param s character for the serial output buffer
* @throws Exception
*/
public static void write(char[] s) throws Exception {
out.write(s);
out.flush();
} // write

/** write a string with CR at the end to the output buffer
* @param s string for the serial output buffer
* @throws Exception
*/
public static void writeln(String s) throws Exception {
out.write(s);
out.write('\r');
out.flush();
System.out.println("write port: " + s + "\n"); // for debugging
} // writeln

/** receives a character string from the serial line
* @return received character string from ME
* @throws Exception
* Remark: Some mobile phones don't send one byte immediate after the other
* byte to the PC. Thus it is necessary to check (about) 5 times after
* a delay that all bytes are received. It is also important to collect
* the bytes not too fast, because this can result in some lost bytes.
*/
public static String read() throws Exception {
int n, i;
char c;
String answer = new String("");

do { // wait until the first byte is received
Thread.sleep(100); // wait at least 100 msec [Timing]
} while (in.ready() == false);

for (i = 0; i < 10; i++) { // look 5 times for character string to receive
//----- collect all characters from the serial line
while (in.ready()) { // there is a byte available
n = in.read(); // get the byte from the serial line
if (n != -1) { // one byte received
c = (char)n; // convert the received integer to a character
answer = answer + c; // collect the characters from the serial line
Thread.sleep(1); // wait 1 msec between every collected byte from the mobile phone [Timing]
} // if
else break; // no more bytes available
} // while
Thread.sleep(100); // wait 100 msec [Timing]
} // for
System.out.println("read port: " + answer + "\n"); // for debugging
return answer; // give the received string back to the caller
} // read


/** close the connection via the serial line
* @throws Exception
*/
public static void close() throws Exception {
try {
port.close();
System.out.println("close port\n"); // for debugging
} // try
catch (Exception e) {
SMS.showText("Error: close port failed: " + e);
} // catch
} // close


}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2006
Added on Jul 31 2006
0 comments
270 views