我遇到了这个奇怪的错误......它的原因是什么
Process: com.justedhak.www.i, PID: 17041
android.content.res.Resources$NotFoundException: String resource ID #0xa
at android.content.res.Resources.getText(Resources.java:1334)
at android.widget.TextView.setText(TextView.java:4917)
at com.justedhak.www.i.DBadapter.getView(DBadapter.java:60)
at android.widget.AbsListView.obtainView(AbsListView.java:2820)
at android.widget.GridView.onMeasure(GridView.java:1064)
at android.view.View.measure(View.java:18557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:607)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:674)
at android.view.View.measure(View.java:18557)
我这么称呼它
DBadapter adapter = new DBadapter(getApplicationContext(), R.layout.grid_item_layout, Objects);
这是适配器
public class DBadapter extends ArrayAdapter<Objects> {
private static Uri[] mUrls = null;
private static String[] strUrls = null;
private String[] mNames = null;
private Cursor cc = null;
private Context mcontext;
private int layoutResourceId;
private List<?> listitems;
public DBadapter(Context context, int layoutResourceId, List<Objects> listitem) {
super(context, layoutResourceId, listitem);
this.layoutResourceId = layoutResourceId;
this.mcontext = context;
this.listitems = listitem;
System.out.println("entering adapter");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("entering adapter1");
View row = convertView;
final ViewHolder holder;
if (row == null) {
LayoutInflater inflater = LayoutInflater.from(mcontext);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.imageTitle = (TextView) row.findViewById(R.id.Nameview);
holder.imageView = (ImageView) row.findViewById(R.id.imageView);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
Objects item = getItem(position);
System.out.println("item.getUrl() ");
System.out.println(item.getUrl());
Picasso.with(mcontext).setIndicatorsEnabled(true);
holder.imageTitle.setText(item.getId());
Picasso.
with(mcontext).
load(item.getUrl())
.placeholder(R.drawable.logo)
.fit()
.noFade()
.into(holder.imageView);
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("OnImageButton", "Clicked");
Intent intnt = new Intent(mcontext, SingleViewActivity.class);
intnt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Bitmap imageID=holder.imageView;
//intnt.putExtra("ImageId", imageID);
mcontext.startActivity(intnt);
Toast.makeText(mcontext, "intent",
Toast.LENGTH_LONG).show();
}
});
return row;
}
static class ViewHolder {
TextView imageTitle;
ImageView imageView;
}
}
网格项layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/Nameview"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:maxLines="2"
android:background="#ea4070"
android:textSize="12sp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="190dp"
android:gravity="center"
android:layout_below="@+id/Nameview"
/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:maxLines="2"
android:layout_below="@+id/imageView"
android:ellipsize="marquee"
android:textSize="12sp"
android:background="#c9c9c9"/>
</RelativeLayout>
答案 0 :(得分:1)
要将Integer
值设置为任意Widget
(TextView
,EditText
等等。),请始终将其转换为String
,然后设置。
holder.imageTitle.setText(String.valueOf(item.getId()));
setText
有多种方法,一种采用String
,另一种采用int
作为resource id
。如果你传递一个整数,它将尝试查找相应的字符串资源ID - 它找不到,导致Resources$NotFoundException
。
答案 1 :(得分:1)
holder.imageTitle.setText(item.getId()+"");