java - 错误“找不到符号 - 方法 isCompleted()

标签 java arraylist count

我不断收到此错误“找不到符号 - 方法 isCompleted()”,但我已经声明了它。我做错了什么???

private boolean isCompleted;

public boolean isCompleted()
{
return isCompleted = true;
}

public int getJobsWaiting()
{        
    int count = 0;
    int i = 0;
    while (i < jobList.size())
    {
        if(!jobList.get(i).isCompleted())
        {
            count = count + 1;
        }
        i = i+1;
    }
    return count;
}

最佳答案

import java.util.ArrayList;
import java.util.List;

public class Jobs {
    List<Job> jobList = null;

    public void createJobs(){
        jobList = new ArrayList<Job>();

        // create three jobs
        for(int index = 0; index < 3; index++){
            jobList.add(new Job());
        }

    }

    public List<Job> getJobs(){
        return jobList;
    }

    public int getJobsWaiting()
    {        
        int count = 0;
        int i = 0;
        while (i < jobList.size())
        {
            if(!jobList.get(i).isCompleted())
            {
                count = count + 1;
            }
            i = i+1;
        }
        return count;
    }


    class Job {

        private boolean isCompleted;


        public boolean isCompleted()
        {
            return isCompleted;
        }

    }

    public static void main(String[] args) {
        Jobs myJob = new Jobs();
        myJob.createJobs();

        System.out.println(myJob.getJobsWaiting()); // return 3

        List<Job> jobs = myJob.getJobs();

        for(int index = 0; index < 3; index++){
            System.out.println(jobs.get(index).isCompleted());
        }
    }
}

jobList.get(i) 应该返回一个包含 isCompleted() 的对象。因此,请确保您调用的是正确的对象。

关于java - 错误“找不到符号 - 方法 isCompleted(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20313586/

相关文章:

java - 需要制作一个1000行的JTable

java - 指定单向 @OneToOne JPA 映射的所有者

java - 子类的ArrayList不能赋值给父类(super class)的ArrayList

java - java 8中静态变量存储在哪里?

java - 使用 Lucene 索引 zip 文件

java - 带有字符串和数组列表的 HashMap - 错误消息

C#如何判断ArrayList是否包含具有特定属性的对象

SQL - 获取最大值

sql - 在 MySQL 中获取表的行数?

sql - 如何在BigQuery中添加一列总行数