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 trialD J W
6,095 PointsSTORMY HAS STOPPED.
Stormy crashes when pressing the HOURLY button.
LOGCAT: 04-01 09:23:20.631 1350-1350/projects.wellsjava.stormy W/EGL_genymotion﹕ eglSurfaceAttrib not implemented 04-01 09:23:20.631 1350-1350/projects.wellsjava.stormy W/ResourceType﹕ No package identifier when getting value for resource number 0x0000002c 04-01 09:23:20.631 1350-1350/projects.wellsjava.stormy D/AndroidRuntime﹕ Shutting down VM 04-01 09:23:20.631 1350-1350/projects.wellsjava.stormy W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4cdbb20) 04-01 09:23:20.635 1350-1350/projects.wellsjava.stormy E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: projects.wellsjava.stormy, PID: 1350 android.content.res.Resources$NotFoundException: String resource ID #0x2c at android.content.res.Resources.getText(Resources.java:244) at android.widget.TextView.setText(TextView.java:3888) at projects.wellsjava.stormy.adapters.HourAdapter$HourViewHolder.bindHour(HourAdapter.java:62) at projects.wellsjava.stormy.adapters.HourAdapter.onBindViewHolder(HourAdapter.java:35) at projects.wellsjava.stormy.adapters.HourAdapter.onBindViewHolder(HourAdapter.java:16) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:4138) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3448) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2237) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)
CODE:
package projects.wellsjava.stormy.adapters;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import projects.wellsjava.stormy.R;
import projects.wellsjava.stormy.weather.Hour;
public class HourAdapter extends RecyclerView.Adapter<HourAdapter.HourViewHolder> { Line 16
private Hour[] mHours;
public HourAdapter(Hour[] hours) {
mHours = hours;
}
@Override
public HourViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.hourly_list_item, parent, false);
HourViewHolder viewHolder = new HourViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(HourViewHolder holder, int position) {
holder.bindHour(mHours[position]); line 35
}
@Override
public int getItemCount() {
return mHours.length;
}
public class HourViewHolder extends RecyclerView.ViewHolder {
public TextView mTimeLabel;
public TextView mSummaryLabel;
public TextView mTemperatureLabel;
public ImageView mIconImageView;
public HourViewHolder(View itemView) {
super(itemView);
mTimeLabel = (TextView) itemView.findViewById(R.id.timeLabel);
mSummaryLabel = (TextView) itemView.findViewById(R.id.summaryLabel);
mTemperatureLabel = (TextView) itemView.findViewById(R.id.temperatureLabel);
mIconImageView = (ImageView) itemView.findViewById(R.id.iconImageView);
}
public void bindHour(Hour hour) {
mTimeLabel.setText(hour.getHour());
mSummaryLabel.setText(hour.getSummary());
mTemperatureLabel.setText(hour.getTemperature()); line 62
mIconImageView.setImageResource(hour.getIconId());
}
}
}
4 Answers
Steve Hunter
57,712 PointsYes, you need to moosh the getTemperature()
as it returns a number. Add + ""
after your code and before the ;
That converts the number to a string.
Should work!
Steve.
Steve Hunter
57,712 PointsI saw that the error was on line 62 and that the error was shouting about setting text. I knew that the getTemperature()
method returns a number and that you were trying to use it as if it were text by passing the result of getTemperature
into a setText
method.
The two together mean that the solution is to convert the number to a string. There's various elegant ways of doing that with casting or method calls but just adding an empty string to it does the trick just as well!!
Hope that helps .
Steve.
D J W
6,095 PointsThanks Steve, missed that one. Did you see that in the logcat? If you did, where?
D J W
6,095 PointsGot it, Thanks.
Dan
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsmTemperatureLabel.setText(hour.getTemperature() + "");