1. 程式人生 > >java執行時報 super constructor GameObject() is undefined. Must explicitly invoke another constructor的錯誤

java執行時報 super constructor GameObject() is undefined. Must explicitly invoke another constructor的錯誤

話不多說,上程式碼:

package com.dyy.game;

import java.awt.Graphics;
import java.awt.Image;

public class Plane extends GameObject{
	public void drawSelf(Graphics g) {
		g.drawImage(img,(int)x,(int)y,null);
		x++;
	}
	
	public Plane(Image img,double x,double y){
		this.img = img;
		this.x = x;
		this.y = y;
		// TODO Auto-generated constructor stub
	}

}

這裡public plane這行報錯,具體情況是這樣:

然後我看了下論壇裡面大家的解決辦法:

在構造方法第一行加入super(),然後就好了。雖然不是什麼大錯誤,但是值得警示:

構造方法中super()必須寫在第一行!