Error android.content.res.Resources $ NotFoundException: String resource ID # 0xbb8 on Android

1

I get the following error:

  

android.content.res.Resources $ NotFoundException: String resource ID # 0xbb8

Error log:

09-29 19:23:27.975 E/AndroidRuntime: FATAL EXCEPTION: main
  Process: app.descubrirosona.lite, PID: 27051
  android.content.res.Resources$NotFoundException: String resource ID #0xbb8
      at android.content.res.Resources.getText(Resources.java:299)
      at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
      at android.widget.TextView.setText(TextView.java:4138)
      at app.descubrirosona.lite.adapters.RouteAdapter.onBindViewHolder(RouteAdapter.java:92)
      at app.descubrirosona.lite.adapters.RouteAdapter.onBindViewHolder(RouteAdapter.java:26)
      at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5825)

the line of the code RouteAdapter.java:92

holder.tvDistance.setText(item.getDistance());
    
asked by Webserveis 29.09.2016 в 19:34
source

2 answers

2

The error:

  

android.content.res.Resources $ NotFoundException: String resource ID # 0xbb8

It may be that the resource is not found since the file R.java (Auto Generable File) was not generated correctly; although in latest versions of Android Studio I have not seen happen.

Currently it is more common as it happens in this case: Unfortunately, MiAplicacion has stopped

The method used setText() expects to receive a value of type String but for some reason it received a int and tries to interpret the value as a resource id:

TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(123);

A quick solution is using String.valueOf() :

TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(String.valueOf(123));

(The reason to use String.valueOf() is that with any value it would not produce an error, even if the variable to be displayed using setText() is of value NULL )

This also applies to the setHint() method.

    
answered by 29.09.2016 / 20:11
source
2

The error indicates that a String was expected to normally show it when it is obtained from numeric data.

To solve a cast must be made, for example if it is from an integer:

Integer.toString(int);
    
answered by 29.09.2016 в 19:34