【问题标题】:GetResourceNames returns null for MPXJ Task methodGetResourceNames 为 MPXJ 任务方法返回 null
【发布时间】:2013-01-23 06:32:14
【问题描述】:

我正在尝试使用 MPXJ - Java 从 MS Project 2010 .mpp 文件中提取基本任务和资源信息。我打开文件并转储所有任务没有问题,但是在尝试访问分配给任务的资源时出现问题。我正在调用 Task.GetResourceNames(),但它每次都返回 null。我也尝试过调用 Task.GetResourceAssignments(),但这也每次都返回 null。

我创建了一个非常非常简单的项目,其中包含一个摘要任务、三个子任务,它们链接在一起,并为每个任务分配了不同的资源。

当我运行我的程序时,我看到了所有的任务,但是对 GetResourceNames() 的调用仍然返回 null。

我是不是通过错误的界面来处理这个问题?

【问题讨论】:

    标签: mpxj


    【解决方案1】:

    您可以在 javadoc 中看到,对于 mpp 文件,GetResourceNames() 始终返回 null。 要从特定任务中获取资源名称,我就是这样做的:

                List<ResourceAssignment> Resources = task.getResourceAssignments();
    // getResourceAssignments() return a list of ResourceAssignment of a specific task.
                Iterator i = Resources.iterator();
    
                while (i.hasNext()) {
                    ResourceAssignment ra = (ResourceAssignment) i.next();
                    Resource r = ra.getResource();
    // we get the resource from the resource assignment
                    System.out.println("\t Assigned Resources : " + r.getName());
    // print the name of the Resource. If you want to do the same than GetResourceNames, just add each name in a String and you will have the same results at the end.
                } 
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2012-06-13
      • 2015-10-10
      • 1970-01-01
      相关资源
      最近更新 更多