Java error: constructor cannot be applied to given types

It compiled and it is still wrong

Java error: constructor cannot be applied to given types

This page is part of Intro to Java with Greenfoot. It assumes you have reached lesson 3.9. Opening it is not counted against you and is not tracked as progress.

The message

constructor X in class X cannot be applied to given types

What it actually means

You created an object with a different set of arguments than any of its constructors accepts. Usually this appears the moment you add your first constructor.

The usual causes

Ranked by how often each one turns out to be the answer. Work down the list.

  1. You wrote a constructor with parameters, which removes the free no-argument one, and old new Enemy() calls no longer match.
  2. The number of arguments does not match the constructor.
  3. The arguments are in the wrong order or the wrong types.

How to fix it

Either pass the arguments the constructor asks for at every creation site, or add a second no-argument constructor that supplies sensible defaults. Both constructors can coexist and Java picks by what you pass.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]