cannot resolve symbol

zpwly 2003-07-02 11:23:36
编译下面两段代码(第二个)时出现cannot resolve symbol错误,为什么!
原码如下:

package serial;
/**
*
* This class implements the buffer area to store incoming data from the serial
* port.
*
*/
public class SerialBuffer
{
private String Content = "";
private String CurrentMsg, TempContent;
private boolean available = false;
private int LengthNeeded = 1;
/**
*
* This function returns a string with a certain length from the incomin
* messages.
*
* @param Length The length of the string to be returned.
*
*/
public synchronized String GetMsg(int Length)
{
LengthNeeded = Length;
notifyAll();
if (LengthNeeded > Content.length())
{
available = false;
while (available == false)
{
try
{
wait();
} catch (InterruptedException e) { }
}
}
CurrentMsg = Content.substring(0, LengthNeeded);
TempContent = Content.substring(LengthNeeded);
Content = TempContent;
LengthNeeded = 1;
notifyAll();
return CurrentMsg;
}
/**
*
* This function stores a character captured from the serial port to the
* buffer area.
*
* @param t The char value of the character to be stored.
*
*/
public synchronized void PutChar(int c)
{
Character d = new Character((char) c);
Content = Content.concat(d.toString());
if (LengthNeeded < Content.length())
{
available = true;
}
notifyAll();
}
}
...全文
4421 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohaiz 2003-07-03
  • 打赏
  • 举报
回复
看看屏幕的拷贝,没有问题.
把两个java放在一起编译.

[zxh@spider serial]$ ls -l
总用量 8
-rw-r--r-- 1 zxh develop 604 7月 3 12:36 ReadSerial.java
-rw-r--r-- 1 zxh develop 1181 7月 3 12:35 SerialBuffer.java
[zxh@spider serial]$
[zxh@spider serial]$ javac *.java
[zxh@spider serial]$
[zxh@spider serial]$
[zxh@spider serial]$ ls -l
总用量 16
-rw-r--r-- 1 zxh develop 601 7月 3 12:36 ReadSerial.class
-rw-r--r-- 1 zxh develop 604 7月 3 12:36 ReadSerial.java
-rw-r--r-- 1 zxh develop 1104 7月 3 12:36 SerialBuffer.class
-rw-r--r-- 1 zxh develop 1181 7月 3 12:35 SerialBuffer.java
zpwly 2003-07-03
  • 打赏
  • 举报
回复
我在serial文件夹下编译:
C:\serial>javac ReadSerial.java
ReadSerial.java:11: cannot resolve symbol
symbol : class SerialBuffer
location: class serial.ReadSerial
private SerialBuffer ComBuffer;
^
ReadSerial.java:21: cannot resolve symbol
symbol : class SerialBuffer
location: class serial.ReadSerial
public ReadSerial(SerialBuffer SB, InputStream Port)
^
2 errors
怎么回事呀?
我用javac -d ReadSerial.java
没报什么编译错误,但是在serial文件夹下根本没有ReadSerial.class文件!
为什么呀.....
zpwly 2003-07-03
  • 打赏
  • 举报
回复
我在serial文件夹下编译:
C:\serial>javac ReadSerial.java
ReadSerial.java:11: cannot resolve symbol
symbol : class SerialBuffer
location: class serial.ReadSerial
private SerialBuffer ComBuffer;
^
ReadSerial.java:21: cannot resolve symbol
symbol : class SerialBuffer
location: class serial.ReadSerial
public ReadSerial(SerialBuffer SB, InputStream Port)
^
2 errors
怎么回事呀?
我用javac -d ReadSerial.java
没报什么编译错误,但是在serial文件夹下根本没有ReadSerial.class文件!
为什么呀.....
hlding 2003-07-03
  • 打赏
  • 举报
回复
请告知你的详细错误信息
罗海雄 2003-07-03
  • 打赏
  • 举报
回复
不好意思
-d .
-d <directory> Specify where to place generated class files
zpwly 2003-07-03
  • 打赏
  • 举报
回复
高手呀
hlding 2003-07-03
  • 打赏
  • 举报
回复
上一条只是一个建议而已,虽然在Coding的时候是麻烦了一些,但这样可以减少潜在的错误,其他地方都写的不错!
hlding 2003-07-03
  • 打赏
  • 举报
回复
对了,程序本身是没有错误的,但在对象的定义时最好能够赋上初值,比如private String CurrentMsg, TempContent;能改为:
private String CurrentMsg="";
private String TempContent="";
是最好的,因为这样一来可以避免出现空指针错误:Exception:java.lang.NullPointerException
hlding 2003-07-03
  • 打赏
  • 举报
回复
以下的前提是保证你的环境变量设置完全正确:
假如当前工作目录为E:\JAVA\Test
1)将ReadSerial.java和SerialBuffer.java保存在当前工作目录下;
2)在当前目录下建立一个文件夹serial,也就是你的跟在package后的包名;
3)先编译SerialBuffer.java,将生成的SerialBuffer.class文件拷贝到serial文件夹下;
A.E:\JAVA\Test>javac SerialBuffer.java //生成SerialBuffer.class文件
B.将E:\JAVA\Test\SerialBuffer.class拷贝到E:\JAVA\Test\serial\SerialBuffer.class
4)再回到当前工作目录下编译ReadSerial.java就不会出现错误了;
E:\JAVA\Test>javac ReadSerial.java
一切OK!
xiaohaiz 2003-07-02
  • 打赏
  • 举报
回复
to rollingpig(rollingpig) :
你用的哪个版本的javac? javac什么时候多出一个-D选项了?

to 楼主:
不过细看之下确实有一个地方会出现cannot resolve symbol错误,出在SerialBuffer类的puChar方法的文档注释,如果运行javadoc估计会出这个错:cannot resolve symbol t

/**
*
* This function stores a character captured from the serial port to the
* buffer area.
*
* @param t The char value of the character to be stored. [<--- here is t]
*/
public synchronized void PutChar(int c) [<--- here is c]
zpwly 2003-07-02
  • 打赏
  • 举报
回复
javac -D 中的-D是什么意识呀
罗海雄 2003-07-02
  • 打赏
  • 举报
回复
只是编译时写的不对
你用javac -D .试试看!!
xiaohaiz 2003-07-02
  • 打赏
  • 举报
回复
编译没有错误.
zpwly 2003-07-02
  • 打赏
  • 举报
回复
代码二:
package serial;
import java.io.*;
/**
*
* This class reads message from the specific serial port and save
* the message to the serial buffer.
*
*/
public class ReadSerial extends Thread
{
private SerialBuffer ComBuffer;
private InputStream ComPort;
/**
*
* Constructor
*
* @param SB The buffer to save the incoming messages.
* @param Port The InputStream from the specific serial port.
*
*/
public ReadSerial(SerialBuffer SB, InputStream Port)
{
ComBuffer = SB;
ComPort = Port;
}
public void run()
{
int c;
try
{
while (true)
{
c = ComPort.read();
ComBuffer.PutChar(c);
}
} catch (IOException e) {}
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧