android.content.res.Resources$NotFoundException: String resource ID




Asked on July 09, 2015
I am working with listview and adapter in android.

public class Employee {
    public int empid;
    public String name;
    public Employee(int id, String name) {
        this.empid = id;
        this.name = name;
    }
}

My adapter code is 

TextView empid = (TextView) view.findViewById(R.id.empid);
empid.setText(emp.empid);
TextView empname = (TextView) view.findViewById(R.id.empname);
empname.setText(emp.name);

Throwing error, what is problem here. Stacktrace is given below.

07-09 07:27:00.630: E/AndroidRuntime(768): android.content.res.Resources$NotFoundException: String resource ID #0x1
07-09 07:27:00.630: E/AndroidRuntime(768): at android.content.res.Resources.getText(Resources.java:244)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.TextView.setText(TextView.java:3888)
07-09 07:27:00.630: E/AndroidRuntime(768): at com.concretepage.EmployeeAdapter.getView(EmployeeAdapter.java:37)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.AbsListView.obtainView(AbsListView.java:2255)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.ListView.makeAndAddView(ListView.java:1790)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.ListView.fillDown(ListView.java:691)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.ListView.fillFromTop(ListView.java:752)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.ListView.layoutChildren(ListView.java:1616)
07-09 07:27:00.630: E/AndroidRuntime(768): at android.widget.AbsListView.onLayout(AbsListView.java:2087)
07-09 07:27:00.630: E/AndroidRuntime(768):






Replied on July 09, 2015
The problem is with line
empid.setText(emp.empid)

when integer value is passed, it searches for resource ID and if not found then it throws error.
You can fix it by passing value as string.

empid.setText(String.valueOf(emp.empid))



Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us