線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1288
推到 Plurk!
推到 Facebook!

请教extends的问题

尚未結案
fangwy
中階會員


發表:99
回覆:139
積分:62
註冊:2003-09-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-14 16:51:11 IP:218.5.xxx.xxx 未訂閱
我的代码如下: import java.io.*; import java.net.*; import java.util.*; public class MulticastServer{ public static void main(String args[]) throws java.io.IOException { new MulticastServerThread().start(); //启动一个服务器线程 } } class MulticastServerThread extends QuoteServerThread //从QuoteServerThread继承得到新的服务器线程类MulticastServerThread { private long FIVE_SECONDS=5000; //定义常量,5秒钟 public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 } . . . } //服务器线程 class QuoteServerThread extends Thread { protected DatagramSocket socket=null; //记录和本对象相关联的DatagramSocket对象 protected BufferedReader in=null; //用来读文件的一个Reader protected boolean moreQuotes=true; //标志变量,是否继续操作 public QuoteServerThread() throws IOException { this("QuoteServerThread"); } public QuoteServerThread(String name) throws IOException { super(name); //调用父类的构造函数 socket=new DatagramSocket(4445); //在端口4445创建数据报套接字 try{ in= new BufferedReader(new FileReader("one-liners.TXT")); //打开一个文件,构造相应的BufferReader对象 }catch(FileNotFoundException e) { //异常处理 System.err.println("Could not open quote file. Serving time instead."); //打印出错信息 }catch(IOException e){} } . . . } 可是编译时提示: MulticastServer.java:9: cannot resolve symbol symbol : constructor MulticastServerThread () location: class MulticastServerThread new MulticastServerThread().start(); ^ 1 error 我将下面一段注释掉: /* public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 }*/ 编译时又提示 MulticastServer.java:16: unreported exception java.io.IOException in default constructor class MulticastServerThread extends QuoteServerThread ^ 1 error 我是一个JAVA的初学者,请各位大大指导,谢谢!
rogan321
高階會員


發表:21
回覆:307
積分:200
註冊:2003-05-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-14 17:29:50 IP:203.204.xxx.xxx 未訂閱
Hi~fangwy你下面紅色地方的變數是什麼型態,有宣告嗎~
引言: 我的代码如下: import java.io.*; import java.net.*; import java.util.*; public class MulticastServer{ public static void main(String args[]) throws java.io.IOException { new MulticastServerThread().start(); //启动一个服务器线程 } } class MulticastServerThread extends QuoteServerThread //从QuoteServerThread继承得到新的服务器线程类MulticastServerThread { private long FIVE_SECONDS=5000; //定义常量,5秒钟 public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 } . . . } //服务器线程 class QuoteServerThread extends Thread { protected DatagramSocket socket=null; //记录和本对象相关联的DatagramSocket对象 protected BufferedReader in=null; //用来读文件的一个Reader protected boolean moreQuotes=true; //标志变量,是否继续操作 public QuoteServerThread() throws IOException { this("QuoteServerThread"); } public QuoteServerThread(String name) throws IOException { super(name); //调用父类的构造函数 socket=new DatagramSocket(4445); //在端口4445创建数据报套接字 try{ in= new BufferedReader(new FileReader("one-liners.TXT")); //打开一个文件,构造相应的BufferReader对象 }catch(FileNotFoundException e) { //异常处理 System.err.println("Could not open quote file. Serving time instead."); //打印出错信息 }catch(IOException e){} } . . . } 可是编译时提示: MulticastServer.java:9: cannot resolve symbol symbol : constructor MulticastServerThread () location: class MulticastServerThread new MulticastServerThread().start(); ^ 1 error 我将下面一段注释掉: /* public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 }*/ 编译时又提示 MulticastServer.java:16: unreported exception java.io.IOException in default constructor class MulticastServerThread extends QuoteServerThread ^ 1 error 我是一个JAVA的初学者,请各位大大指导,谢谢!
fangwy
中階會員


發表:99
回覆:139
積分:62
註冊:2003-09-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-14 17:38:06 IP:218.5.xxx.xxx 未訂閱
对这个变量没有宣告,代码是另一个程序移过来的,没发现,因前面所说的那两个问题出现,所以JAVA出还没报这个错.rogan321兄,我该如何解决上面的问题呢?
rogan321
高階會員


發表:21
回覆:307
積分:200
註冊:2003-05-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-14 17:40:23 IP:203.204.xxx.xxx 未訂閱
前面的問題即是呼叫extend的建構元所產生的問題原則上就這樣就可以了~ DatagramSocket socket=new DatagramSocket(4445); ................. 其餘的動作........... 發表人 - rogan321 於 2005/01/14 17:43:55
系統時間:2024-05-09 19:35:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!