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 trialMiguel Nunez
1,081 PointsWhy am I getting "null" in the console when I run code?
Thank you!
Nourez Rawji
3,303 PointsIt's hard to say when you don't have any code for us to look over ;)
Ilja Ankipovits
1,630 PointsPlease Help, i have the same problem with "null"
public class Example {
public static void main(String[] args) { // Your amazing code goes here... System.out.println("We are making a new PEZ Dispenser"); PezDispenser dispenser = new PezDispenser ("Yoda"); System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() );
String before = dispenser.swapHead("Darth Vader"); System.out.printf("It wast %s but Chris swither it to %s %n", before, dispenser.getCharacterName());
}
}
Console: We are making a new PEZ Dispenser The dispenser is null It wast null but Chris swither it to Darth Vader
3 Answers
SIDI YAYA TRAORE
1,766 PointsPlease copy and send us your code for review, that would help greatly in trying to help you solve your problem
Ilja Ankipovits
1,630 PointsPlease Help, i have the same problem with "null"
public class Example {
public static void main(String[] args) { // Your amazing code goes here... System.out.println("We are making a new PEZ Dispenser"); PezDispenser dispenser = new PezDispenser ("Yoda"); System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() );
String before = dispenser.swapHead("Darth Vader"); System.out.printf("It wast %s but Chris swither it to %s %n", before, dispenser.getCharacterName());
}
}
Console:
We are making a new PEZ Dispenser
The dispenser is null
It wast null but Chris swither it to Darth Vader
Mouz Asfaw Aligaz
1,827 PointsMiguel and Ilja, Check PezDispenser.java for the "name" variable in the constructor and change it to "characterName" without the quotes. That was what solved it for me.
markmneimneh
14,132 Pointsmarkmneimneh
14,132 Pointswhat code?