java socket程序出现运行时错误,帮忙看一下

来源:百度知道 编辑:UC知道 时间:2024/06/01 20:03:13
//Aclient.java
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
public class Aclient extends Applet implements Runnable,ActionListener{
JButton button;JTextField textF;JTextArea textA;
Socket socket;Thread thread;
DataInputStream in;DataOutputStream out;
public void init(){
setBackground(new Color(120,153,137));
setLayout(new BorderLayout());
button=new JButton("发送消息");
textF=new JTextField(20);
textA=new JTextArea(20,30);
setSize(450,350);
JPanel p=new JPanel();
p.add(textF);
p.add(button);
p.add(textA);
//add(textA,"Center");
add(p,"South");
button.addActionListener(this);
}
public void start(){
try{
socket=new Socket("localhost",4331);
in=new DataInputStream(socket.getInputStream());

把服务端的代码发过来,我运行到
socket=new Socket("localhost",4331);
这条就捕获到异常,然后
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
这两条就跳过。
由于in 和 out 没有进行初始化就出现了NullPointerException

我也不知道,但是楼上的肯定是在忽悠

他已经提示没有找到Alient.class。

try{........}
catch (ClassNotFoundException e)
{
System.out.println(e.toString()) ;
}

你将看到异常的具体信息.........方便调试
这比你直接看代码 找错误来得方便

楼上的都错了,同志,我回答你,是因为applet不支持socket!原因是安全性,就好象file框不让赋值一样。

没关防火墙 这个要关的.