站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2ME 专题继承Layer类时出了问题,编译通不过,又找不到错误?高手们看下(实在是没有多少可用分了)

继承Layer类时出了问题,编译通不过,又找不到错误?高手们看下(实在是没有多少可用分了)

摘要: 继承Layer类时出了问题,编译通不过,又找不到错误?高手们看下(实在是没有多少可用分了)


错误提示停在了构造函数上,实在看不出那里有了问题。。。。。


代码:
------------------------------------------------
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.*;

public class CharSprite extends Layer implements Runnable {

private static String charFileName="/actions.png";//人物图片文件名
private static String weaponFileName="/weapon.png";//武器图片文件名
static final private int FBS=20;//帧速:20ms一帧
private boolean isPlay=false;//播放状态
public int laststate=1;//人物上一个状态
public int state=1;//人物状态
public boolean isAttack=false;//人物攻击状态
//人物状态
static final public int STAND_RIGHT=1;//向右站立
static final public int STAND_LEFT=2;//向左站立
static final public int RUN_RIGHT=7;//向右前进
static final public int RUN_LEFT=8;//向左前进
static final public int ATTACK_RIGHT=21;//向右攻击
static final public int ATTACK_LEFT=22;//向左攻击
//动作序列
final private int sr_seq[]={0};//向右站立
final private int sl_seq[]={4};//向左站立
final private int pr_seq[]={8,9,10,11};//向右停止前进
final private int pl_seq[]={12,13,14,15};//向左停止前进
final private int rr_seq[]={16,17,18,19,20,//向右前进
21,22,23,24,25,26,27,28,29,30,31};
final private int rl_seq[]={32,33,34,35,36,//向左前进
37,38,39,40,41,42,43,44,45,46,47};
final private int jr_seq[]={48,49,50,51,52,53};//向右跳跃
final private int jl_seq[]={56,57,58,59,60,61};//向左跳跃
final private int asr_seq[]={64,65,65,65,66,67,68,69,70,71};//向右站立攻击
final private int asl_seq[]={72,73,73,73,74,75,76,77,78,79};//向左站立攻击
final private int wr_seq[]={5,6,7,7,7,8,9};//向右挥动的武器
final private int wl_seq[]={0,1,2,2,2,3,4};//向左挥动的武器

private LayerManager layers;
private Sprite character;
private Sprite weapon;

public CharSprite(){
layers=new LayerManager();
character=new Sprite(Image.createImage(charFileName),22,34);
weapon=new Sprite(Image.createImage(weaponFileName),47,13);
layers.append(character);
this.setPosition(x,y);
}
。。。。。。
省略了若干方法
。。。。。。

public void run() {
while(isPlay){
this.nextFrame();
try {
Thread.sleep(FBS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public void paint(Graphics g) {
// TODO Auto-generated method stub
layers.paint(g,0,0);
}


直接把错误信息全部发出来.


SeverityDescriptionResourceIn FolderLocationCreation Time
2Implicit super constructor Layer() is undefined. Must explicitly invoke another constructorCharSprite.javaDemo_2Dline 432006年4月3日 23:51:11



好乱,重贴一下:

Implicit super constructor Layer() is undefined. Must explicitly invoke another constructor


信息已经很清楚了啊,必须明确调用构造函数


Layer是个抽象类
况且super()也试过了,一样。


super constructor Layer() is undefined. -- 超类有默认构造函数吗


Layer没有公有构造函数的哦


继承Layer必须声明和他在同一个包中,然后调用他的保护类型的构造函数super(width,height)


package javax.microedition.lcdui.game;

import javax.microedition.lcdui.Graphics;


public class TestLayer extends Layer {

public TestLayer()
{
super(100,100);
}
public void paint(Graphics arg0) {

}
}
这样写就没有错了


学习 ...


↑返回目录
前一篇: GameCanvas 类中使用keyReleased()的问题
后一篇: 屏幕部分刷新的问题!