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 trialElias Svoba
14,347 PointsgetRemainingCharacterCount
I need help i've written my code like that but i keep getting an error message so i can't seem to find the error i'm making.
public class Tweet {
private String text;
public static final int MAX_CHARS = 140;
public Tweet(String text) {
while(text.length() < MAX_CHARS) {
this.text = text;
}
}
public String getText() {
return text;
}
public int getRemainingCharacterCount() {
return MAX_CHARS - text.length();
}
public void setText(String text) {
this.text = text;
}
}
Elias Svoba
14,347 PointsPhew your solution works wonders thanks a lot Jeroen Oosterwijk. I've also reported it to TeamTreehouse. Happy coding.
1 Answer
Ruslan Georgiev
604 Pointspublic Tweet(String text) {
while(text.length() < MAX_CHARS) {
this.text = text;
Hi Elias Svoba I assume the purpose of the code is to check if the tweet is longer than 140 characters. You should use “if” instead of "while". Every time you input text shorter the 140 characters you enter an infinite loop.
Elias Svoba
14,347 PointsThanks Ruslan Georgiev.
jeroenoosterwijk
5,456 Pointsjeroenoosterwijk
5,456 PointsHey Elias Svoba
When I pass in the exact code you passed in, I too get an error without explanation, it seems to me there is some bug that causes the program that checks your solution to time out. Even though I'm not a pro, it seems to me your code is correct. You might consider reporting this bug to TeamTreehouse by shooting them an e-mail at help@teamtreehouse.com.
Here is a solution that does work: