This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jaymo
Jaymo wrote ...

2013/11/27

Error: Constructor ScoreBoard in class ScoreBoard cannot be applied to given types;

Jaymo Jaymo

2013/11/27

#
Can't get my code to work. Error: Constructor ScoreBoard in class ScoreBoard cannot be applied to given types; required: no arguments; found: int; reason:actual and formal arguments lists differ in length This is in my WombatWorld Class. If I remove the score and leave it "addObject(new ScoreBoard(),6,3);", it compiles but it doesn't return a score and doesn't say that the game is over.
 
public void gameOver(int score)
    {
        addObject(new ScoreBoard(score),6,3);
        Greenfoot.stop();
    }
ScoreBoard class shown below
 
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
import java.util.Calendar;
/**
 * Write a description of class ScoreBoard here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ScoreBoard extends Actor
{
   
    public static final float FONT_SIZE = 48.0f;
    public static final int WIDTH = 400;
    public static final int HEIGHT = 300;
    public ScoreBoard()
    {
        makeImage("Game Over");
    }
    private void makeImage(String title)
    {
        GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
        image.setColor(new Color(0,0,0,160));
        image.fillRect(0,0, WIDTH, HEIGHT);
        image.setColor(new Color(255,255,255,100));
        image.fillRect(5,5, WIDTH-10,HEIGHT-10);
        Font font = image.getFont();
        font=font.deriveFont(FONT_SIZE);
        image.setFont(font);
        image.setColor(Color.WHITE);
        image.drawString(title,60,100);
        setImage(image);
    }
}

I've declared score in my Leaf class as int score=0; Can anybody help me please?
danpost danpost

2013/11/27

#
Like the error message says: you do not have a constructor in the ScoreBoard class that accepts an 'int' value as an argument. The only constructor you have in that class accepts no arguments ('public ScoreBoard()' -- nothing within the parenthesis). You can either change the one you already have to accept an 'int' value or create another constructor to do that.
Jaymo Jaymo

2013/11/27

#
Thanks for that. I'm not very good at this stuff. to be honest with you I have been following a worksheet which obviously isn't a 100 accurate. How would you change the one that I have allready got? Thanks for your time.
danpost danpost

2013/11/27

#
Please refer to the Java tutorial page on Passing Information to a Method or a Constructor.
Jaymo Jaymo

2013/11/28

#
Thanks for your help. Much appreciated.
You need to login to post a reply.