$ NotFoundException Resources in Android

The problem is the $ NotFoundException resource in tv2.settext (), I donโ€™t know why I have TreeMap, inside the pizza name and counter. Please, help!

Vocation:

for (Pizza pizza : list) { if(map.containsKey(pizza.title)) { int i = map.get(pizza.title); map.remove(pizza.title); map.put(pizza.title, i++); } else { map.put(pizza.title, 1); } } 

Pizza:

 public class Pizza implements Comparable<String> { public String title; public int rate; public String date; public Bitmap picture; public int id; @Override public int compareTo(String another) { // TODO Auto-generated method stub return this.title.compareTo(another); } } 

Error code:

 for (Entry<String, Integer> entry : map.entrySet()) { tv.setText(entry.getKey()); tv2.setText((Integer)entry.getValue()); //Error occures here tv.setGravity(Gravity.LEFT); tv2.setGravity(Gravity.RIGHT); TableRow tr1 = new TableRow(this); tr1.addView(tv); tr1.addView(tv2); tl.addView(tr1, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } } 

Error:

 10-04 09:04:40.475: ERROR/AndroidRuntime(954): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1 
+6
source share
4 answers

Change tv2.setText((Integer)entry.getValue()); on the

 tv2.setText(entry.getValue().toString()); 

do it

  TableRow tr1 = new TableRow(this); for (Entry<String, Integer> entry : map.entrySet()) { tv.setText(entry.getKey()); tv2.setText((Integer)entry.getValue()); //Error occures here tv.setGravity(Gravity.LEFT); tv2.setGravity(Gravity.RIGHT); tr1.addView(tv); tr1.addView(tv2); tl.addView(tr1, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } } 
+23
source

You should use: tv2.setText(entry.getValue().toString());

In addition, you do not need the following line of code:

 map.remove(pizza.title); 

All you need to write: map.put(pizza.title, i++); becaues "put" Map method replaces the old value.

+3
source
 tv2.setText((Integer)entry.getValue()); 

Divide your Integer by String

0
source

I don't know what you're trying to do, but you obviously aren't using R.string.my_title_or_so for setText . Integer you pass to this method must be a valid (generated) identifier from your class R Or you hide the number before the line, for example. num + "" .

0
source

Source: https://habr.com/ru/post/898574/


All Articles