TO: yuzl32(Hello!有酒醉) 为什么我在编译过程中,两个文件都有错误? Servicer 错误是: Servicer.java:26:cannot resolve symbol symbol :variable TCPServerDemo location:class Servicer TCPServerDemo.count--;Servicer.java:27:cannot resolve symbol symbol :variable TCPServerDemo location:class Servicer if(TCPServerDemo.count==0)Servicer.java:28:cannot resolve symbol symbol :variable TCPServerDemo location:class Servicer TCPServerDemo.bRunning = false;TCPServerDemo错误: TCPServerDemo.java:18:cannot resolve symbol symbol :class Servicer location:class TCPServerDemo new Thread( new Servicer(s)).start(); 这是什么原因? 帮帮忙,谢了
没问题,我刚试过! package jbb;import java.net.*; import java.io.IOException;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class mymain { static int count=0; static boolean bRunning = true; public static void main(String[] args){ try{ ServerSocket ss = new ServerSocket(8003);//boolean bRunning = true; while(bRunning){ Socket s = ss.accept(); if(s!=null) count++; new Thread( new Servicer(s)).start(); } ss.close(); } catch(IOException e){ e.printStackTrace(); } } }---------------------------------------------------- package jbb; import java.net.*; import java.io.*;public class Servicer implements Runnable { private Socket s; public Servicer(Socket s){ this.s = s; } public void run(){ try{ InputStream ips = s.getInputStream(); OutputStream ops = s.getOutputStream(); BufferedReader br = new BufferedReader( new InputStreamReader(ips)); PrintWriter pw = new PrintWriter(ops,true); while(true){ String strLine = br.readLine(); if(strLine.equalsIgnoreCase("quit")){ mymain.count--; if(mymain.count==0) mymain.bRunning = false; break; } System.out.println(strLine+"From"+s.getInetAddress().toString()+":"+s.getPort()); String strEcho = (new StringBuffer(strLine).reverse()).toString(); pw.println(strLine +"------>"+strEcho); } br.close(); pw.close(); s.close(); } catch(IOException e){ e.printStackTrace(); } } }
import java.net.*;
import java.io.IOException;
public class TCPServerDemo {
static int count=0;
static boolean bRunning = true;
public static void main(String[] args){
try{
ServerSocket ss = new ServerSocket(8003);
//boolean bRunning = true;
while(bRunning){
Socket s = ss.accept();
if(s!=null)
count++;
new Thread( new Servicer(s)).start();
}
ss.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}import java.net.*;
import java.io.*;public class Servicer implements Runnable {
private Socket s;
public Servicer(Socket s){
this.s = s;
}
public void run(){
try{
InputStream ips = s.getInputStream();
OutputStream ops = s.getOutputStream();
BufferedReader br = new BufferedReader( new InputStreamReader(ips));
PrintWriter pw = new PrintWriter(ops,true);
while(true){
String strLine = br.readLine();
if(strLine.equalsIgnoreCase("quit")){
TCPServerDemo.count--;
if(TCPServerDemo.count==0)
TCPServerDemo.bRunning = false;
break;
}
System.out.println(strLine+"From"+s.getInetAddress().toString()+":"+s.getPort());
String strEcho = (new StringBuffer(strLine).reverse()).toString();
pw.println(strLine +"------>"+strEcho);
}
br.close();
pw.close();
s.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}连接通信:
telnet 127.0.0.1 8003
Servicer.java:30: 需要 "class" 或 "interface"
import java.net.*;
^
Servicer.java:31: 需要 "class" 或 "interface"
import java.io.*;
^
2 错误
D:\JavaProduct>java Servicer
Exception in thread "main" java.lang.NoSuchMethodError: mainD:\JavaProduct>java TCPServerDemo
什么反映也没有。并没有输出:连接通信:
telnet 127.0.0.1 8003 啊?
为什么我在编译过程中,两个文件都有错误?
Servicer
错误是:
Servicer.java:26:cannot resolve symbol
symbol :variable TCPServerDemo
location:class Servicer
TCPServerDemo.count--;Servicer.java:27:cannot resolve symbol
symbol :variable TCPServerDemo
location:class Servicer
if(TCPServerDemo.count==0)Servicer.java:28:cannot resolve symbol
symbol :variable TCPServerDemo
location:class Servicer
TCPServerDemo.bRunning = false;TCPServerDemo错误:
TCPServerDemo.java:18:cannot resolve symbol
symbol :class Servicer
location:class TCPServerDemo
new Thread( new Servicer(s)).start();
这是什么原因?
帮帮忙,谢了
package jbb;import java.net.*;
import java.io.IOException;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class mymain {
static int count=0;
static boolean bRunning = true;
public static void main(String[] args){ try{
ServerSocket ss = new ServerSocket(8003);//boolean bRunning = true; while(bRunning){ Socket s = ss.accept();
if(s!=null)
count++;
new Thread( new Servicer(s)).start();
} ss.close();
}
catch(IOException e){ e.printStackTrace();
}
}
}----------------------------------------------------
package jbb;
import java.net.*;
import java.io.*;public class Servicer implements Runnable {
private Socket s; public Servicer(Socket s){ this.s = s;
} public void run(){ try{
InputStream ips = s.getInputStream();
OutputStream ops = s.getOutputStream(); BufferedReader br = new BufferedReader( new InputStreamReader(ips));
PrintWriter pw = new PrintWriter(ops,true);
while(true){ String strLine = br.readLine(); if(strLine.equalsIgnoreCase("quit")){ mymain.count--;
if(mymain.count==0)
mymain.bRunning = false;
break;
}
System.out.println(strLine+"From"+s.getInetAddress().toString()+":"+s.getPort());
String strEcho = (new StringBuffer(strLine).reverse()).toString();
pw.println(strLine +"------>"+strEcho);
} br.close();
pw.close(); s.close();
}
catch(IOException e){ e.printStackTrace();
}
}
}
http://www.regexlab.com/zh/jar2exe/demo3.htm
我编译时就是出那样的错误
我就直接保存了一个TCPServerDemo.java和Servicer.java文件。然后再编译时就有问题。这是为什么?
我对java不怎么熟悉,所以请帮帮忙。
谢了
------------------------
package TCPIP;import java.io.*;
import java.net.*;
import java.io.IOException;
class TCPServerDemo{
static int count=0;
static boolean bRunning = true;
public static void main(String[] args){try{
ServerSocket ss = new ServerSocket(8003);//boolean bRunning = true;while(bRunning){ Socket s = ss.accept();
if(s!=null)count++;
new Thread( new Servicer(s)).start();
} ss.close();
}
catch(IOException e){ e.printStackTrace();
}
}
}//-----------------------------------class Servicer implements Runnable {
private Socket s;public Servicer(Socket s){this.s = s;
}public void run(){try{
InputStream ips = s.getInputStream();
OutputStream ops = s.getOutputStream();BufferedReader br = new BufferedReader( new InputStreamReader(ips));
PrintWriter pw = new PrintWriter(ops,true);
while(true){String strLine = br.readLine();if(strLine.equalsIgnoreCase("quit")){TCPServerDemo.count--;
if(TCPServerDemo.count==0)
TCPServerDemo.bRunning = false;
break;
}
System.out.println(strLine+"From"+s.getInetAddress().toString()+":"+s.getPort());
String strEcho = (new StringBuffer(strLine).reverse()).toString();
pw.println(strLine +"------>"+strEcho);
}br.close();
pw.close();s.close();
}
catch(IOException e){e.printStackTrace();
}
}
}