[java] android.content.res.Resources$NotFoundException: String resource ID #0x0

I'm developing an Android app which reads data from MySQL database and I faced this error. I have this XML layout:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 


        <TextView android:id="@+id/wardNumber" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_marginLeft="3dp" 
            android:text="Ward Number" 
            android:textSize="22dp"/> 


        <TextView android:id="@+id/dateTime" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_below="@id/wardNumber" 
            android:layout_alignParentRight="true" 
            android:layout_marginRight="3dp" 
            android:text="Date-Time" />

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/dateTime"
            android:layout_alignBottom="@+id/dateTime"
            android:layout_alignLeft="@+id/wardNumber"
            android:layout_marginLeft="3dp" 
            android:text="Name" />

</RelativeLayout> 

And this is the my Java file:

public ApplicationAdapter(Context context, List<Application> items) {
    super(context, R.layout.app_custom_list, items);
    this.items = items;
}

@Override
public int getCount() {
    return items.size();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if(v == null) {
        LayoutInflater li = LayoutInflater.from(getContext());
        v = li.inflate(R.layout.app_custom_list, null);            
    }

    Application app = items.get(position);

    if(app != null) {
      //  ImageView icon = (ImageView)v.findViewById(R.id.appIcon);
        TextView wardNumber = (TextView)v.findViewById(R.id.wardNumber);
        TextView name = (TextView)v.findViewById(R.id.name);
      //  LinearLayout ratingCntr = (LinearLayout)v.findViewById(R.id.ratingCntr);
        TextView dateTime = (TextView)v.findViewById(R.id.dateTime);

  //      if(icon != null) {
  //          Resources res = getContext().getResources();
   //         String sIcon = "com.sj.jsondemo:drawable/" + app.getIcon();
   //         icon.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
   //     }

        if(wardNumber != null) wardNumber.setText(app.getTitle());

        if(name != null) name.setText(app.getTitle());

        if(dateTime != null) {
            dateTime.setText(app.getTotalDl());
          //  NumberFormat nf = NumberFormat.getNumberInstance();
          //  dateTime.setText(nf.format(app.getTotalDl())+" dl");            
        }


    }

    return v;
}
}

When this Activity is called, I receive this error message:

11-24 21:12:03.633:  E/AndroidRuntime(1251):  FATAL EXCEPTION: main
11-24 21:12:03.633:  E/AndroidRuntime(1251): android.content.res.Resources$NotFoundException: String resource ID #0x0
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.content.res.Resources.getText(Resources.java:201)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.TextView.setText(TextView.java:2863)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at com.sj.jsondemo.Appl icationAdapter.getView(ApplicationAdapter.java:53)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.AbsListView.obtainView(AbsListView.java:1430)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.ListView.onMeasure(ListView.java:1127)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.View.measure(View.java:8313)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:701)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.View.measure(View.java:8313)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.View.measure(View.java:8313)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
11-24 21:12:03.633: E/AndroidRuntime(1251):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.View.measure(View.java:8313)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at  android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.View.measure(View.java:8313)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.os.Looper.loop(Looper.java:130)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at java.lang.reflect.Method.invokeNative(Native Method)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at java.lang.reflect.Method.invoke(Method.java:507)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 21:12:03.633:  E/AndroidRuntime(1251):    at dalvik.system.NativeStart.main(Native Method)
11-24 21:12:08.922: I/Process(1251): Sending signal. PID: 1251 SIG: 9

I don't know how to fix this error.

This question is related to java android xml listview

The answer is


Replace

dateTime.setText(app.getTotalDl());

With

dateTime.setText(""+app.getTotalDl());

if you get the values in int you have to use string for that it is throwing the error

before

  holder.villageName.setText(villageModelList.get(position).getVillageName());
    holder.villageCount.setText(villageModelList.get(position).getPeopleCount());
    holder.peopleCount.setText(villageModelList.get(position).getPeopleCount());

after

  holder.villageName.setText(villageModelList.get(position).getVillageName());
    holder.villageCount.setText(String.valueOf(villageModelList.get(position).getPeopleCount()));
    holder.peopleCount.setText(String.valueOf(villageModelList.get(position).getPeopleCount()));

you can solve the error by adding the String.valueOf


The evaluated value for settext was integer so it went to see a resource attached to it but it was not found, you wanted to set text so it should be string so convert integer into string by attaching .toStringe or String.valueOf(int) will solve your problem!


If we get the value as int and we set it to String, the error occurs. PFB my solution,

Textview = tv_property_count;
int property_id;
tv_property_count.setText(String.valueOf(property_id));

When you try to set text in Edittext or textview you should pass only String format.

dateTime.setText(app.getTotalDl());

to

dateTime.setText(String.valueOf(app.getTotalDl()));

You can do it. this is a easy way.

txtTopicNo.setText(10+"");

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to xml

strange error in my Animation Drawable How do I POST XML data to a webservice with Postman? PHP XML Extension: Not installed How to add a Hint in spinner in XML Generating Request/Response XML from a WSDL Manifest Merger failed with multiple errors in Android Studio How to set menu to Toolbar in Android How to add colored border on cardview? Android: ScrollView vs NestedScrollView WARNING: Exception encountered during context initialization - cancelling refresh attempt

Examples related to listview

How to add a ListView to a Column in Flutter? Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView` Best way to update data with a RecyclerView adapter Android Recyclerview vs ListView with Viewholder Get clicked item and its position in RecyclerView How to show an empty view with a RecyclerView? NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference RecyclerView vs. ListView How to implement endless list with RecyclerView? Recyclerview and handling different type of row inflation