当前位置: 技术问答>java相关
急求助!怎样解决无法实例化?
来源: 互联网 发布时间:2015-10-05
本文导语: 我写的一个多线程的socket通信,客户端程序run java applet总是说无法实例化,但是作为java appllication 是成功连接的,请问这是为什么?源程序如下: import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; ...
我写的一个多线程的socket通信,客户端程序run java applet总是说无法实例化,但是作为java appllication 是成功连接的,请问这是为什么?源程序如下:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Client extends Panel
{
//界面设计和添加事件响应
private TextField tf = new TextField();//文本输入框
private TextArea ta = new TextArea();//聊天记录窗口
private Socket socket;
private DataOutputStream dout;
private DataInputStream din;
public Client( String host, int port ) {
setLayout( new BorderLayout() );
add( "North", tf );
add( "Center", ta );
tf.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
processMessage( e.getActionCommand() );
}
} );
//敲回车键以后,与服务器进行连接
try {
socket = new Socket( host, port );
System.out.println( "connected to "+socket );
din = new DataInputStream( socket.getInputStream() );
dout = new DataOutputStream( socket.getOutputStream() );
run();
// 启动一个消息接收的线程
// new Thread( this ).start();
} catch( IOException ie ) { System.out.println( ie ); }
}
// 接收键盘输入并发送消息
private void processMessage( String message ) {
try {
dout.writeUTF( message );
tf.setText( "" );
} catch( IOException ie ) { System.out.println( ie ); }
}
// 在另一个窗口显示聊天消息
public void run() {
try {
while (true) {
String message = din.readUTF();
ta.append( message+"n" );
}
} catch( IOException ie ) { System.out.println( ie ); }
}
static public void main( String args[] ) throws Exception {
String host = "202.197.111.196" ;
int port=9000;
new Client( host, port ) ;
}
}
提示为:载入:无法实例化 Client.class。
java.lang.InstantiationException: Client
at java.lang.Class.newInstance0(Class.java:281)
at java.lang.Class.newInstance(Class.java:249)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:548)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:477)
at sun.applet.AppletPanel.run(AppletPanel.java:290)
at java.lang.Thread.run(Thread.java:536)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Client extends Panel
{
//界面设计和添加事件响应
private TextField tf = new TextField();//文本输入框
private TextArea ta = new TextArea();//聊天记录窗口
private Socket socket;
private DataOutputStream dout;
private DataInputStream din;
public Client( String host, int port ) {
setLayout( new BorderLayout() );
add( "North", tf );
add( "Center", ta );
tf.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
processMessage( e.getActionCommand() );
}
} );
//敲回车键以后,与服务器进行连接
try {
socket = new Socket( host, port );
System.out.println( "connected to "+socket );
din = new DataInputStream( socket.getInputStream() );
dout = new DataOutputStream( socket.getOutputStream() );
run();
// 启动一个消息接收的线程
// new Thread( this ).start();
} catch( IOException ie ) { System.out.println( ie ); }
}
// 接收键盘输入并发送消息
private void processMessage( String message ) {
try {
dout.writeUTF( message );
tf.setText( "" );
} catch( IOException ie ) { System.out.println( ie ); }
}
// 在另一个窗口显示聊天消息
public void run() {
try {
while (true) {
String message = din.readUTF();
ta.append( message+"n" );
}
} catch( IOException ie ) { System.out.println( ie ); }
}
static public void main( String args[] ) throws Exception {
String host = "202.197.111.196" ;
int port=9000;
new Client( host, port ) ;
}
}
提示为:载入:无法实例化 Client.class。
java.lang.InstantiationException: Client
at java.lang.Class.newInstance0(Class.java:281)
at java.lang.Class.newInstance(Class.java:249)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:548)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:477)
at sun.applet.AppletPanel.run(AppletPanel.java:290)
at java.lang.Thread.run(Thread.java:536)
|
你的类没有扩展Applet
|
Panel 类可以直接当 Applet 用吗??
没看过
没看过