简体   繁体   English

带错误android.content.res.Resources $ NotFoundException的sqlite适配器:字符串资源ID#0xa

[英]sqlite adapter with error android.content.res.Resources$NotFoundException: String resource ID #0xa

I faced this strange error .. what the cause of it 我遇到了这个奇怪的错误..原因是什么

  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)

I am calling it such way 我这样称呼

DBadapter adapter = new DBadapter(getApplicationContext(), R.layout.grid_item_layout, Objects);

this is the adapter 这是适配器

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;
    }
}

grid item layout.xml 网格项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>

To set Integer value into any Widget ( TextView , EditText , etc..) always convert it to String and then set. 要将Integer值设置为任何WidgetTextViewEditText等),请始终将其转换为String ,然后进行设置。

 holder.imageTitle.setText(String.valueOf(item.getId()));

There are multiple method of setText , one takes a String and one takes an int as resource id . setText有多种方法,一种使用String ,一种使用int作为resource id If you pass it an integer it will try to look for the corresponding string resource id - which it can't find, result into Resources$NotFoundException . 如果将其传递给整数,它将尝试查找对应的字符串资源id(找不到),结果变成Resources$NotFoundException

holder.imageTitle.setText(item.getId()+"");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:android.content.res.Resources $ NotFoundException:字符串资源ID - Android: android.content.res.Resources$NotFoundException: String resource ID android.content.res.Resources$NotFoundException · 字符串资源 ID # - android.content.res.Resources$NotFoundException · String resource ID # android.content.res.Resources$NotFoundException:字符串资源 ID - android.content.res.Resources$NotFoundException: String resource ID android.content.res.resources notfoundexception $ android.content.res.resources notfoundexception $字符串资源ID#0x1 - android.content.res.resources notfoundexception $android.content.res.resources notfoundexception $ string resource id #0x1 如何消除这个错误 (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff) - how to remove this error (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff) 错误:android.content.res.Resources$NotFoundException:字符串资源 ID #0x1 - Error: android.content.res.Resources$NotFoundException: String resource ID #0x1 无法在 textview 中设置文本。错误:-android.content.res.Resources$NotFoundException:字符串资源 ID #0x0 - Faild to settext in textview.Error:-android.content.res.Resources$NotFoundException: String resource ID #0x0 android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 android.content.res.Resources $ NotFoundException:资源ID#0xffffffff - android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM