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

Code Challenge error java.lang.NullPointerException (Look around JavaTester.java line 250)

In the Code Challenge: Creating a Model Object, on the last Challenge Task my code is as follows:

public class Movie {

private String mTitle; private int mYearReleased;

public String getTitle() { return mTitle; }

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

public int getYearReleased() { return mYearReleased; }

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

When I check the preview it returns:

java.lang.NullPointerException at JavaTester.run(JavaTester.java:250) at JavaTester.main(JavaTester.java:41)

What is going wrong here?

https://teamtreehouse.com/library/build-a-weather-app/working-with-json/creating-a-model-object

1 Answer

the code is

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

  public String getTitle () {
  return mTitle;
  }
   public void setTitle (String title) {
  mTitle = title;
  }
  public int getYearReleased () {
  return mYearReleased;
  }

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

}

That worked, thank you! Looks like I had some inaptly spelled variables. The part that really through me off was the error message. It said something about lines 250 and 41, which I assumed had to do with the code that checks the answer, it just really confused me.

The code challenge says you to ignore m prefix.But you are not ignoring m prefix.That will be the cause for your error. Thank you!