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 trialParth Kaura
4,157 PointsStormy App showing no data . after i click the 7day button? help with error plz.
After pressing the 7DAY button.. the empty msg comes up.. "there is no data to be displayed"
THE BELLOW COME IN THE ANDROID MONITOR::
04-14 17:25:22.706 25655-25668/com.example.kaura.stormy I/MainActivity: From Json:Asia/Kolkata 04-14 17:25:22.712 25655-25668/com.example.kaura.stormy D/MainActivity: 5:27 PM 04-14 17:25:22.743 25655-25665/com.example.kaura.stormy I/art: Background sticky concurrent mark sweep GC freed 24151(1179KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1878KB/3MB, paused 5.761ms total 98.722ms 04-14 17:26:12.880 25655-25672/com.example.kaura.stormy W/EGL_emulation: eglSurfaceAttrib not implemented 04-14 17:26:12.880 25655-25672/com.example.kaura.stormy W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad79ede0, error=EGL_SUCCESS 04-14 17:26:13.395 25655-25672/com.example.kaura.stormy E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb4055870
4 Answers
Dimitrios Zarkadas
8,912 PointsAdd this line at the end of onCreate() in DailyForecastActicity : setListAdapter(adapter);
Dimitrios Zarkadas
8,912 PointsMy code is almost exactly like yours.
My "convertView = LayoutInflater..." line is also highlighting the NULL parameter, but no errors are created.
The only difference is that I don't have any exception handlers in the getView() method. So, try removing the try-catch block and running you app again.
Parth Kaura
4,157 Pointswithout the try catch the app is crashing.. error is..
04-15 00:27:16.101 2367-2367/com.example.kaura.stormy E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.kaura.stormy, PID: 2367 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.kaura.stormy.adapters.DayAdapter.getView(DayAdapter.java:65)
public class DayAdapter extends BaseAdapter {
private Context mContext;
private Day[] mDays;
public DayAdapter(Context context, Day[] days){
mContext = context;
mDays = days;
}
@Override
public int getCount() {
return mDays.length;
}
@Override
public Object getItem(int position) {
return mDays[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null){
//brand new
convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
holder = new ViewHolder();
holder.iconImageView = (ImageView)convertView.findViewById(R.id.iconImageView);
holder.temperatureLabel = (TextView)convertView.findViewById(R.id.tempretureLable);
holder.dayLabel = (TextView)convertView.findViewById(R.id.dayNameLabel);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
Day day = mDays[position];
holder.iconImageView.setImageResource(day.getIconId());
holder.temperatureLabel.setText(day.getTemperatureMax() + "");
if (position == 0){
holder.dayLabel.setText("Today");
}
else {
holder.dayLabel.setText(day.getDayOfTheWeek());
}
return convertView;
}
private static class ViewHolder {
ImageView iconImageView;
TextView temperatureLabel;
TextView dayLabel;
}
}
Dimitrios Zarkadas
8,912 PointsI have the exact same code as above and no problems.
Check your getDayOfTheWeek() method. The NullPointerException means there's no string to setText().
Parth Kaura
4,157 PointsThe day of week are showing up. and has no problem. cause when i comment out the temperaturemax line out.. it works fine.. thats y i put a try catch around temperturemax.
anyway.. i think ill go through the code from the start.. i must have missed something..
thank you so much for your insight.
cheers!!
Taylor Bryant
7,395 Pointsholder.temperatureLabel = (TextView)convertView.findViewById(R.id.tempretureLable);
There is a typo in R.id.tempretureLable
Parth Kaura
4,157 PointsParth Kaura
4,157 Pointshey Dimitrios.. thanks for the help.. i totally forgot to set the adapter..
now i have a new problem..
i was showing a null point exception error.. so i handled it with a try and catch block.. but now the temperaturemax are not showing on the 7day activity.. they are empty.
its showing the following error..
E/DayAdapter: Fatal Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.kaura.stormy.adapters.DayAdapter.getView(DayAdapter.java:69)
line 69 in DayAdapter is the holdder.temperatureLabel one below.
try { holder.temperatureLabel.setText(day.getTemperatureMax() + ""); } catch (Exception e) { Log.e(TAG, "Fatal Exception", e); }
also above in the line
convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
its high lighting the null and says" avoid passing a null as a view root..
help please!!
parth kaura!!