2 suce92 suce92 于 2014.09.04 10:13 提问

安卓编程问题求解,资源文件不能被引用。

categorybar_item_background cannot be resolved or is not a field
报如上错误。
下面是代码。


package com.suice.ptxw;
import java.util.List;
import java.util.Map;
import android.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class CustomSimpleAdapter extends SimpleAdapter
{

public CustomSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
{
    super(context, data, resource, from, to);
}

public View getView(int position, View convertView, ViewGroup parent)
{
    View v = super.getView(position, convertView, parent);
    //更新第一个TextView的背景
    if (position==0)
    {
        TextView categoryTitle = (TextView)v;
         ** *categoryTitle.setBackgroundResource(R.drawable.categorybar_item_background);* ** 
        categoryTitle.setTextColor(0XFFFFFFFF);
    }
    return v;
}

}


下面是部分R文件内容。


public static final class drawable {
    public static final int btbj=0x7f020000;
     **public static final int categorybar_item_background=0x7f020001;** 
    public static final int flbj=0x7f020002;
    public static final int ic_launcher=0x7f020003;
    public static final int main_background=0x7f02000b;
    public static final int newslist_item_background=0x7f02000c;
    public static final int sx=0x7f020004;
    public static final int sxing=0x7f020005;
    public static final int xsbj=0x7f020006;
    public static final int xwdj=0x7f020007;
    public static final int xwdjbj=0x7f020008;
    public static final int xwfgx=0x7f020009;
    public static final int yd=0x7f02000a;
}

求解如何解决该问题。

2个回答

aqswde35025
aqswde35025   2014.09.04 14:11

import android.R;导入了错误的R文件,应该是yourPackageName.R

u012616609
u012616609   2014.09.04 16:40

嗯嗯 同上 你那一步时R引用错了 你引用系统的了 应该引用你自己项目的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!