Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKenneth Phillips
Courses Plus Student 10,188 PointsEnums
./com/example/model/Brand.java:5: error: constructor Brand in enum Brand cannot be applied to given types; JVC, ^ required: String found: no arguments reason: actual and formal argument lists differ in length ./com/example/model/Brand.java:6: error: constructor Brand in enum Brand cannot be applied to given types; SONY, ^ required: String found: no arguments reason: actual and formal argument lists differ in length ./com/example/model/Brand.java:7: error: constructor Brand in enum Brand cannot be applied to given types; COBY, ^ required: String found: no arguments reason: actual and formal argument lists differ in length ./com/example/model/Brand.java:8: error: constructor Brand in enum Brand cannot be applied to given types; APPLE; ^ required: String found: no arguments reason: actual and formal argument lists differ in length 4 errors
Can someone help me sort out the problem?
package com.example.model;
public enum Brand {
// Your code here
JVC,
SONY,
COBY,
APPLE;
private String mDisplayName;
Brand(String displayName) {
mDisplayName = displayName;
}
public String getDisplayName() {
return mDisplayName;
}
}
2 Answers
Simon Coates
28,694 Pointsyou need to pass the arguments through to the constructor.
package com.example.model;
public enum Brand {
JVC("JVC"),
SONY("Sony"),
COBY("Coby"),
APPLE("Apple");
private String mDisplayName;
Brand(String displayName) {
mDisplayName = displayName;
}
public String getDisplayName() {
return mDisplayName;
}
}
(i'd assume that the presence of a constructor means that the default no arg constructor isn't created. If you added a no arg constructor, then the code would be valid from java's perspective, but not satisfy the task instructions)
Martin Gallauner
10,808 PointsHi
I miss the point in the video when Craig explains how to use a argument with the enum?
E.g APPLE ("Apple");
Kenneth Phillips
Courses Plus Student 10,188 PointsKenneth Phillips
Courses Plus Student 10,188 PointsI see what you're saying. Thanks.