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 trialAldrin Cabuniag
3,783 PointsError: Attemp to get length of Null Array
Currently, trying to follow along the Stormy Weather App on the Retrieving Parcelable Array bit however I am getting an error:
NullPointerException: Attempt to get length of null array at com.teamtreehouse.stormy.ui.DailyForecastActivity.onCreate(DailyForecastActivity.java:24)
My code on line 24 is:
mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class);
Code that surrounds line 24:
public class DailyForecastActivity extends ListActivity { private Day[] mDays;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
Intent intent = getIntent();
Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORECAST);
mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class);
DayAdapter adapter = new DayAdapter(this, mDays);
setListAdapter(adapter);
}
I've attempted to refer to a similar question, however the question wasn't followed up therefore no answers. I'm not sure how to check if my parcel arrays are returning "nulls". Any tips would be appreciated :) thanks.
1 Answer
Simon Coates
28,694 PointsError might suggest that
Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORECAST);
is faulty, or the code that should provide the Parcelable is faulty (you haven't shown the code that puts it on the intent). The short is that the above isn't returning anything (ie. is null).
Aaron Goodman
3,953 PointsAaron Goodman
3,953 PointsI'm having the same issue. My code in DailyForecastActivity is the same as above, my code providing the intent( with the parcelable) is below: