Android: android.content.res.Resources$NotFoundException: String resource ID #0x5
(Just assumption, less info of Exception stacktrace)
I think, this line, incercari.setText(valIncercari);
throws Exception
because valIncercari
is int
So it should be,
incercari.setText(valIncercari+"");
Or
incercari.setText(Integer.toString(valIncercari));
android.content.res.Resources$NotFoundException: String resource ID Fatal Exception in Main
Move
Random pp = new Random();
int a1 = pp.nextInt(10);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText(a1);
To inside onCreate()
, and change tv.setText(a1);
to tv.setText(String.valueOf(a1));
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random pp = new Random();
int a1 = pp.nextInt(10);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText(String.valueOf(a1));
}
First issue: findViewById()
was called before onCreate()
, which would throw an NPE.
Second issue: Passing an int directly to a TextView calls the overloaded method that looks for a String resource (from R.string
). Therefore, we want to use String.valueOf()
to force the String
overloaded method.
android.content.res.Resources$NotFoundException: String resource ID #0x1 Error
Instead of
rollNo.setText(items[position].getRollNo());
you should use
rollNo.setText(Integer.toString(items[position].getRollNo()));
If you try to set integer as text, you call method setText(int resID) and application try to set as text some string resource with this resID.
Problem resolving an android.content.res.Resources error
android.content.res.Resources$NotFoundException: String resource ID #0x601ee924
at android.content.res.Resources.getText(Resources.java:348)
at android.widget.TextView.setText(TextView.java:5848)
at com.tex.lightweatherforecast.Activity.HomeActivity$1.onResponse(HomeActivity.java:66)
As shown above, the exception is raised in HomeActivity
in onResponse()
method line (66) where you try to set a text into a TextView
.
So, In HomeActivity
you've:
time_field.setText(response.body().getCurrent().getDt());
And as per documentation, .getDt()
returns an integer, so you can't set it directly to TextView
unless you convert it to a String.
To solve this, replace that line of code with one of:
// 1st
time_field.setText(String.valueOf(response.body().getCurrent().getDt()));
// 2nd
time_field.setText("" + response.body().getCurrent().getDt());
android.content.res.Resources$NotFoundException: String resource ID #0x2b
public void setNumber(View view) {
button = (Button)view;
displayText = display.getText().toString().trim();
char[] characters = displayText.toCharArray();
if (displayText.equals("") || ((!(new String(characters).contains(Character.toString('+')))) && (!(new String(characters).contains(Character.toString('-')))) && (!(new String(characters).contains(Character.toString('x')))) && (!(new String(characters).contains(Character.toString('÷')))))) {
num1 = button.getText().toString().trim();
displayText = displayText + num1;
} else {
num2 = button.getText().toString().trim();
displayText = displayText + num2;
nos = displayText.split(Pattern.quote(operator.toString()));
Log.d("array", "arr: " + Arrays.toString(nos));
number1 = Integer.parseInt(nos[0]);
number2 = Integer.parseInt(nos[1]);
}
display.setText(displayText);
}
Use the above method it will solve your issue. The issue with regular expression syntax.
Error: android.content.res.Resources$NotFoundException: String resource ID #0x1
Toast.makeText(getApplicationContext(), temp.getChildCount(), Toast.LENGTH_SHORT).show();
temp.getChildCount()
returns an int
and the Toast.makeText()
overload that takes an int
argument there expects it to be a resource id. Use the String
overload instead by converting the int
to a string, e.g.
Toast.makeText(getApplicationContext(), "" + temp.getChildCount(), Toast.LENGTH_SHORT).show();
Same issue with the other Toast
.
android.content.res.Resources$NotFoundException: String resource ID #0x4
I think problem is here:
textView.setText(secondsLeft);
try:
textView.setText(String.valueOf(secondsLeft));
It's not possible to place integer values into TextView.
Resources$NotFoundException: String resource ID #0x1
Your problem is here:
private void setQuantityCounter(int count) {
counterTextView.setText(count);
}
When you pass an int
to TextView.setText()
, it is assuming that you're passing a String resource identifier... something like R.string.my_string
(which is an int
under the hood).
It looks like you're just trying to display a count. The easiest way to do this (though not strictly the best way) would be something like this:
private void setQuantityCounter(int count) {
counterTextView.setText("" + count);
}
Related Topics
Android App Crashes When Launched in Debug Mode
Visual Studio (2015) Emulator for Android Not Working - Xde.Exe - Exit Code 3
Android Java Lang Runtimeexception Fail to Connect to Camera Service
How to Have Searched Characters Colored When We Use Searchview in Recyclerview
How to Customize Item Background and Item Text Color Inside Navigationview
Out of Memory Error Imageview Issue
Android: Set Color of Checkbox
Android Countdowntimer - Additional Milliseconds Delay Between Ticks
Find Out If Listview Is Scrolled to the Bottom
Android Compass That Can Compensate for Tilt and Pitch
Check If Battery Optimization Is Enabled or Not for an App
Complete Working Sample of the Gmail Three-Fragment Animation Scenario
Implementing User Choice of Theme
How to Set Default App Launcher Programmatically
How to Open/Display Documents(.Pdf, .Doc) Without External App