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 trialAbdurahman Osman
5,927 PointsI have no idea how to fix this
it keeps giving me error on the return public int getRemainingCharacterCount(){ return MAX_CHARS - text.length(); } }
public class Tweet {
private String text;
public Tweet(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public class MaxChars {
public static final int MAX_CHARS = 140;
}
public int getRemainingCharacterCount() {
return MAX_CHARS - text.length();
}
}
1 Answer
Tornike Shelia
2,781 PointsYou don't have to create the inner class MaxChars , and also as I found out from google, You can't define constant fields in inner class :
8.1.2 Inner Classes and Enclosing Instances
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (ยง8.7) or member interfaces. Inner classes may not declare static members, unless they are compile-time constant fields (ยง15.28).
So to solve the problem , just delete the MaxChars class and just add :
public static final int MAX_CHARS = 140 ;
below the class Tweet and it should work :)