The code is below:
public static void main(String[] args) {
FileInputStream fstream = null;
try {
// Create a stream object containing the license file
fstream = new FileInputStream(“Aspose.Tasks.lic”);
// Instantiate the License class
License license = new License();
// Set the license through the stream object
license.setLicense(fstream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Project asProject = new Project(“Project_blank.mpp”);
com.aspose.tasks.Resource asResource = asProject.getResources().add(“test”);
for (int i = 0; i < 10; i++) {
final long startTime = System.currentTimeMillis();
Task asTask = asProject.getRootTask().getChildren().add(“Root task” + i);
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
asTask.set(Tsk.START, cal1.getTime());
asTask.set(Tsk.FINISH, cal2.getTime());
asTask.set(Tsk.DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.WORK, asProject.getDuration(4, TimeUnitType.Hour));
asTask.set(Tsk.UID, i);
asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
asTask.set(Tsk.IS_CRITICAL, new NullableBool(false));
asTask.set(Tsk.ACTUAL_START, cal1.getTime());
asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());
asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.START, cal1.getTime());
asTask.set(Tsk.FINISH, cal2.getTime());
asTask.set(Tsk.UID, i);
asTask.set(Tsk.WORK, asProject.getDuration(8));
asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
asTask.set(Tsk.NAME, “test” + i);
Integer type = 2;
if (type != null) {
asTask.set(Tsk.CONSTRAINT_TYPE, type.intValue());
}
asTask.set(Tsk.CONSTRAINT_DATE, cal1.getTime());
asTask.set(Tsk.PRIORITY, 500);
asTask.set(Tsk.IS_CRITICAL, new NullableBool(true));
asTask.set(Tsk.TOTAL_SLACK, 3);
asTask.set(Tsk.ACTUAL_START, cal1.getTime());
asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());
asTask.set(Tsk.ACTUAL_DURATION, asProject.getDuration(4, TimeUnitType.Day));
asTask.set(Tsk.PERCENT_COMPLETE, 90);
asTask.set(Tsk.REMAINING_WORK, asProject.getDuration(16));
asProject.getResourceAssignments().add(asTask, asResource);
final long endTime = System.currentTimeMillis();
System.out.println("Total execution time: " + (endTime - startTime));
System.out.println(i);
}
// Save the Project
asProject.save(“task-resource.mpp”, SaveFileFormat.MPP);
System.out.println(“ok”);
}
Open the MPP file, the issue is that the actual finish display ‘N/A’, but when I delete the line ‘com.aspose.tasks.Resource asResource = asProject.getResources().add(“test”);’, the actual finish has correct value.