android.content.res.Resources $ NotFoundException:在setImageResource中

loading...


-1

我的应用程序中出现以下错误 . 提前致谢

我的对象

public ListModel(String mName,int hours,int minutes/*,boolean isDaily*/,Integer imageId){
    this.name = mName;
    this.hours = hours;
    this.minutes = minutes;
    this.totalTime = minutes*60 + hours*3600;  // change in seconds

    this.timeLeft = totalTime;
    this.imageId = imageId;
    this.statusId = statusId;
    this.isDone =false;

    }

public boolean isDone() {
    return isDone;
}

public void setDone(boolean done) {
    isDone = done;
}

public Integer getImageId() {
    return imageId;
}

public Integer getStatusId() {
    return statusId;
}

我的适配器public View getView(最终int位置,@ Nullable View convertView,@ NonNull ViewGroup parent){LayoutInflater layoutInflater = LayoutInflater.from(context); View view = layoutInflater.inflate(resource,null,false);

TextView text1 = (TextView)view.findViewById(R.id.textView1);
    TextView time = (TextView) view.findViewById(R.id.time);
    TextView percent = (TextView)view.findViewById(R.id.percent);
    ImageView icon = (ImageView)view.findViewById(R.id.imageView2);
    ImageView status = (ImageView)view.findViewById(R.id.status);
    TypedArray array ;

    ListModel task = tasklist.get(position);
    time.setText(task.getHours()*60 + task.getMinutes()+"m");
    if(task.getTotalTime()!=0){
    percent.setText((int)(100 - task.getTimeLeft()*100/task.getTotalTime())+"%");
    }
    else {
        percent.setText("0%");
    }
    text1.setText(task.getName());
    if(task.getImageId()!=null) {
        icon.setImageResource(task.getImageId());   //////  Error is here (line 61)
    }else {
        icon.setImageResource(R.drawable.circular);
    }
    if(task.getStatusId()!=null) {
        status.setImageResource(task.getStatusId());
    }else {
        status.setImageResource(R.drawable.pending);
    }

    return view;
}

列表中对象的初始化

temp2 = new ListModel(data.getStringExtra("name"), data.getIntExtra("hours", 0),
                        data.getIntExtra("minutes", 0),
                        data.getIntExtra("icon", R.drawable.workout)); 



08-22 20:40:37.074 12676-12676/com.example.lenovo.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lenovo.myapplication, PID: 12676
android.content.res.Resources$NotFoundException: Resource ID #0x7f02007a
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:201)
    at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:94)
    at android.content.res.Resources.getValue(Resources.java:1304)
    at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:236)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:199)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
    at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
    at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:73)
    at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:81)
    at com.example.lenovo.myapplication.ListAdapter.getView(ListAdapter.java:68)
    at android.widget.AbsListView.obtainView(AbsListView.java:2367)
    at android.widget.ListView.measureHeightOfChildren(ListView.java:1326)
    at android.widget.ListView.onMeasure(ListView.java:1233)
1回答

  • 0

    尝试将ImageView保留在java代码文件之外的问题所在的位置 . 编译/构建项目,然后在java文件中使用它,您必须将其设置为资源 .

loading...

评论

暂时没有评论!