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

Cant solve a fatal exception

Hi All,

I was following the video on this app, and I cant get it to work. Help would really be appreciated, as I spent lots of time trying to solve:) Below is the error I get: 2020-06-09 21:02:08.756 30563-30563/com.example.golflist E/xample.golflis: Invalid ID 0x00000000. 2020-06-09 21:02:08.760 30563-30563/com.example.golflist E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.golflist, PID: 30563 android.content.res.Resources$NotFoundException: String resource ID #0x0 at android.content.res.Resources.getText(Resources.java:348) at android.widget.TextView.setText(TextView.java:5831) at com.example.golflist.ListAdapter.getView(ListAdapter.java:49) at android.widget.AbsListView.obtainView(AbsListView.java:2366) at android.widget.ListView.makeAndAddView(ListView.java:2052) at android.widget.ListView.fillDown(ListView.java:786) at android.widget.ListView.fillFromTop(ListView.java:847) at android.widget.ListView.layoutChildren(ListView.java:1826) at android.widget.AbsListView.onLayout(AbsListView.java:2165) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:508) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:753) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:696) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2020-06-09 21:02:08.778 30563-30589/com.example.golflist E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1

And here is the code where error is popping:

public class ListAdapter extends BaseAdapter { private final Context mContext; private final Hole[] mHoles; public ListAdapter(Context context, Hole[] holes){ mContext=context; mHoles=holes; }

@Override
public int getCount() {
    return mHoles.length;
}

@Override
public Object getItem(int position) {
    return mHoles[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if(convertView==null){
       convertView= LayoutInflater.from(mContext).inflate(R.layout.list_item,null);
       holder= new ViewHolder();
       holder.holeLabel= convertView.findViewById(R.id.holeLabel);
       holder.strokeCount= convertView.findViewById(R.id.strokeCount);
       holder.removeStrokeButton= convertView.findViewById(R.id.removeStrokeButton);
       holder.addStrokeButton= convertView.findViewById(R.id.addStrokeButton);
       convertView.setTag(holder);
    } else{
        holder=(ViewHolder) convertView.getTag();
    }
    holder.holeLabel.setText(mHoles[position].getmLabel());
    holder.strokeCount.setText(mHoles[position].getmStrokeCount());
    holder.removeStrokeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int updatedStrokeCount=mHoles[position].getmStrokeCount()-1;
            if (updatedStrokeCount<0) updatedStrokeCount=0;
            mHoles[position].setmStrokeCount(updatedStrokeCount);
            holder.strokeCount.setText(updatedStrokeCount+ "");
        }
    });
    holder.addStrokeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int updatedStrokeCount=mHoles[position].getmStrokeCount()+1;
            mHoles[position].setmStrokeCount(updatedStrokeCount);
            holder.strokeCount.setText(updatedStrokeCount);
        }
    });
    return convertView;
}
private static class ViewHolder {
    TextView holeLabel;
    TextView strokeCount;
    Button removeStrokeButton;
    Button addStrokeButton;
}

}