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 trialMohamed Mandour
7,783 Pointswhy is these POJO wrong?
public class Contact{ private int id; private String fristName; private String lastName; private String email;
public int getId() {
return id;
}
public String getFristName() {
return fristName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public void setId(int id) {
this.id = id;
}
public void setFristName(String fristName) {
this.fristName = fristName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setEmail(String email) {
this.email = email;
}
}
public class Contact{
private int id;
private String fristName;
private String lastName;
private String email;
public int getId() {
return id;
}
public String getFristName() {
return fristName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public void setId(int id) {
this.id = id;
}
public void setFristName(String fristName) {
this.fristName = fristName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setEmail(String email) {
this.email = email;
}
}
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! There are a couple of things going on here. First, your class file is missing the package declaration. I will give you the start: package com.team...
and I think you can figure it out from there.
But also, your variable names must be the same as the ones asked for by the challenge. It is asking for one of the private field names to be firstName
. But in every instance of this you have transposed the "r" and the "i", resulting in various capitalizations of fristName
instead of firstName
.
When I include the correct package declaration and fix the spelling errors in your methods and variables containing firstName
or FirstName
, your code passes!
I think you can get it with these hints, but let me know if you're still stuck!
Mohamed Mandour
7,783 PointsHi, Jennifer thank you for your help, I have correct the spelling mistake. but not the package and I do not know why do we have to include package declaration since we not coding in IDE.
Jennifer Nordell
Treehouse TeacherI'm unsure why it's being required in the challenge, but the very first Bummer message is that there is something wrong with your package declaration. It is clearly expecting it as when I add the package declaration, it works. My guess is that they want to make sure you know how it is done. This is, after all, a test of your skills.
Mohamed Mandour
7,783 PointsThank you for your help done, I have another problem if you may help me, I have been getting an error regarding video (creating repository) here is the error message
APPLICATION FAILED TO START
Description: Field gifRepository in controller.GifController required a bean of type '.repositoryGifRepository' that could not be found. Action: Consider defining a bean of type 'repository.GifRepository' in your configuration.
Basically, I have created a gifRepository with a list of gifs and one method to find gif by name called findByName().
package repository;
import java.time.LocalDate; import java.util.Arrays; import java.util.List;
import org.springframework.stereotype.Component;
import model.Gif;
@Component public class GifRepository {
private static final List<Gif> ALL_GIFS = Arrays.asList(
new Gif("android-explosion", LocalDate.of(2015,2,13), "Chris Ramacciotti", false),
new Gif("ben-and-mike", LocalDate.of(2015,10,30), "Ben Jakuben", true),
new Gif("book-dominos", LocalDate.of(2015,9,15), "Craig Dennis", false),
new Gif("compiler-bot", LocalDate.of(2015,2,13), "Ada Lovelace", true),
new Gif("cowboy-coder", LocalDate.of(2015,2,13), "Grace Hopper", false),
new Gif("infinite-andrew", LocalDate.of(2015,8,23), "Marissa Mayer", true)
);
// find by name
public Gif findByName(String name){
for (Gif i: ALL_GIFS){
if( i.getName().equals(name))
return i;
}
return null;
}
}
Then in the controller, I am trying use this method to dynamically find the name of the gifs by name as shown in the gifDetails method. package controller;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping;
import repository.GifRepository; import model.Gif;
@Controller public class GifController {
@Autowired
private GifRepository gifRepository;
@Autowired
private Gif gif;
@RequestMapping("/")
public String listGifs()
{
return "home";
}
@RequestMapping("/gif")
public String gifDetails(ModelMap modelMap)
{
gif = gifRepository.findByName("android-explosion"); // here What I belive is the problem
modelMap.put("gif", gif);
return "gif-details";
}
}
having said that, I want to know what is the problem and how can I fix it? if you need further explanation please ask me. I appreciate your patience and looking forward to the answer.