The serializable class Myplayer does not declare a static final serialVersionUID field of type long

The serializable class Myplayer does not declare a static final serialVersionUID field of type long

2011-11-02 17:49 3110006414  |  浏览 4799 次
java中写Applet小程序的问题,使用Eclipse集成开发工具。程序没有错误,可以运行,但是在public class 后面的类名有下划线,显示一个警告,“The serializable class Myplayer does not declare a static final serialVersionUID field of type long”。
部分代码:
import java.awt.*;
import java.applet.*;

public class Myplayer extends Applet{
	String file="不可一世.au";       
	AudioClip clip;
	Button b1,b2,b3;
	Choice choice=new Choice();
	
	public void init(){
		setSize(400,50);
		choice.add(file);                 //设置可拉框,显示当前播放的歌名
		add(choice);
		b1=new Button("start");                 //设置三个按钮,分别为start,loop,stop。
		b2=new Button("loop");
		b3=new Button("stop");
		add(b1);
		add(b2);
		add(b3);
		clip=this.getAudioClip(getDocumentBase(),file);      //取得声音文件
	}

这到底是什么意思,怎么可以解决。。。??
2011-11-03 15:12 提问者采纳
这个警告是提示你要实现序列化。Applet需要在网络上进行传输(对象会离开内存),所以需要实现序列化,以便用户在接收时通过反序列化就可以将你传输的对象重新在内存中还原。
追问:
请问怎样才能实现序列化???
追答:
Applet的父类  public abstract class Component implements ImageObserver, MenuContainer,
                                           Serializable{
已经实现过序列化Serializable了,这里只是需要一个对象的标识,

public class Myplayer extends Applet{
private static final long serialVersionUID = 1L; //这个是缺省的
或者 private static final long serialVersionUID = -8534844170998963067L; //自动生成的。
这两句随便写一个都行

或者
@SuppressWarnings("serial")
public class AudioApplet extends Applet  {

不要写个注解忽略这个警告
提问者评价
谢谢啦!!这个问题困惑了我好久了,搜过很多答案,讲了一大堆,晕了。。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值