我收到以下錯誤消息,我似乎無法找出問題所在。非常感謝任何幫助。錯誤消息全文: -StringTokenizer的問題
BaseStaInstance.java:68:找不到符號
符號:構造的StringTokenizer(java.lang.Object中,java.lang.String中)
位置:級Java。 util.StringTokenizer st = new StringTokenizer(buf,「,」);
^
這裏,BaseStaInstance是我主要的公共類。
實現此的StringTokenizer的類是如下: -
類ServerConnect擴展Thread {
Socket skt;
int iProcessId, iInProcessId;
int iOwnTimeStamp, iInTimeStamp;
ServerConnect scnt = null;
ObjectOutputStream myOutput;
ObjectInputStream myInput;
ServerConnect(){}
ServerConnect(Socket connection, int iProcessNo) {
this.skt = connection;
this.iProcessId = iProcessNo;
}
public void run() {
try {
//initialize the object "scnt" using the parameterized constructor
ServerConnect scnt = new ServerConnect(skt, iProcessId);
myInput = new ObjectInputStream(skt.getInputStream());
while(true) {
try{
iOwnTimeStamp = Global.iTimeStamp;
Object buf = myInput.readObject();
//if we got input, print it out and write a message back to the remote client...
if(buf != null){
scnt.replyChoice(buf);
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
} catch(IOException e) {
e.printStackTrace();
}
}
void replyChoice(Object buf){
try{
String sDeferReply = "";
myOutput = new ObjectOutputStream(skt.getOutputStream());
//the place where the basestation reads the request from the other basestation
System.out.println("Server read:[ "+buf+" ]");
//extract out the process id and the timestamp from the incoming request
buf = buf.toString();
***StringTokenizer st = new StringTokenizer(buf,",");***
//skip the word request
st.nextToken();
iInProcessId = Integer.parseInt(st.nextToken());
iInTimeStamp = Integer.parseInt(st.nextToken());
//check request is made
//there is a possibility of entering the else loop only on the very first iteration
//the control flows into the if loop even if one request has been made
if(iOwnTimeStamp != 0){
//if the incoming request has a larger timestamp (logical clock value, process id) than the current process, we defer the reply
if(iOwnTimeStamp < iInTimeStamp || iProcessId < iInProcessId){
sDeferReply="iInTimeStamp"+","+"iInProcessId";
Global.v.addElement(new String(sDeferReply));
}
//incoming request has a smaller timestamp than the basestation request itself
else{
myOutput.writeObject("Reply");
myOutput.flush();
}
}
//if the current process is in the critical section then we defer replies
else if(Global.iCriticalSection==1){
sDeferReply="iInTimeStamp"+","+"iInProcessId";
Global.v.addElement(new String(sDeferReply));
}
//start of execution of the thread, there is a possibility that the basestation hasn't issued a request
else{
myOutput.writeObject("Reply");
myOutput.flush();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
一個實現的StringTokenizer函數具有***包圍它的一部分。
在此先感謝任何可能幫助我的人。
嘿,感謝您的幫助,它的工作。實際上我嘗試使用buf.toString()將buf轉換爲字符串,但是我將它存儲回buf中,該buf是object類型的。 – 2010-02-28 03:20:03
很高興幫助。而且因爲你是新手,所以stackoverflow的工作方式是,如果某人的回答很有幫助,那麼你就可以投票給他們聲望點。這就是我答案左邊的箭頭和檢查點。 – polygenelubricants 2010-02-28 03:24:24
哦,好的。好吧,我嘗試了投票,但我不斷收到一條消息,因爲我需要15點聲望才能符合條件。 :) – 2010-02-28 03:50:11