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 trial

Android Build a Weather App (2015) Working with JSON Creating a Model Object

Setters return void?

In POJO challenge of the Build a Weather App section, I'm supposed to create getters and setters. When I try to do return mTitle, it tells me that setters should return void. But when I try return void, it gives me a compiler error about invalid start of expression.

How do I get past this?

Movie.java
public class Movie {
 private String mTitle;
  private int mYearReleased;

  public String getTitle() {
   return mTitle; 
  }

  public String setTitle(String title) {
    mTitle = title;
    return void;
  }

  public int getYearReleased() {
   return mYearReleased; 
  }

  public int setYearReleased(int year) {
    mYearReleased = year;
    return void;
  }
}

1 Answer

This is where my lack of Java experience comes up... I just needed to set the actual function type to void:

public void setYearReleased(int year) { mYearReleased = year; }