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
isral bustami
Courses Plus Student 5,932 Pointshow can i fix null pointer exception
i'm trying to get string that i passed from another activity and trying to setText in TextView with value that i passed but i keep getting null.pointer.exception
public class DailyForecastActivity extends ListActivity {
private Day[] mDays;
private Forecast mForecast;
@InjectView(R.id.locationLabel) TextView mLocationLabel;
private String mLoc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
Intent intent = getIntent();
mLoc = intent.getStringExtra("location");
String location = mLoc;
mLocationLabel.setText(location);
Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORECAST);
mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class );
DayAdapter adapter = new DayAdapter(this, mDays);
setListAdapter(adapter);
}
mLocationLabel always null
did i set it in wrong way..??
2 Answers
Dan Johnson
40,533 PointsI believe with ButterKnife you need to call:
ButterKnife.inject(this);
After the call to setContentView in onCreate.
isral bustami
Courses Plus Student 5,932 Pointshell yeah.. how can i forget that.. thank you.. much