PrimaveraPMFileWriter throws Exception at write(..)
Multi platform library to read and write schedule data
Brought to you by:
joniles
PrimaveraPMFileWriter throws exception in getDuration (environment: .NET / Visual Studio 2012)
MPXJ version 5.15
Example: I modified the sample "MpxjConvert"
AbstractProjectReader reader = new net.sf.mpxj.primavera.PrimaveraXERFileReader();
ProjectFile projectFile = reader.read(inputFile);
net.sf.mpxj.primavera.PrimaveraPMFileWriter writer = new net.sf.mpxj.primavera.PrimaveraPMFileWriter();
writer.write(projectFile, outputFile);
File created is empty, because in writer.write occurs an exception. it seems that in PrimaveraPMFileWriter.getDuration some object is null:
ex.ToString() "System.NullReferenceException: Object reference not set to an instance of an object.\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.getDuration(Duration )\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.writeActivity(Task )\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.writeTask(Task )\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.writeTasks()\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.write(ProjectFile projectFile, OutputStream stream)\r\n at net.sf.mpxj.writer.AbstractProjectWriter.write(ProjectFile projectFile, String fileName)\r\n at MpxjQuery.MpxjQuery.LoadTestExport(Int32 iterations) in d:\\Local\\3rdParty\\mpxj\\src.net\\MpxjQuery\\MpxjQuery.cs:line 115\r\n at MpxjQuery.MpxjQuery.Main(String[] args) in d:\\Local\\3rdParty\\mpxj\\src.net\\MpxjQuery\\MpxjQuery.cs:line 19" string
[System.NullReferenceException] = {"Object reference not set to an instance of an object."}
Source = "mpxj-for-csharp"
StackTrace = " at net.sf.mpxj.primavera.PrimaveraPMFileWriter.getDuration(Duration )\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.writeActivity(Task )\r\n at net.sf.mpxj.primavera.PrimaveraPMFileWriter.writeTask(Task )\r\n at net.sf.mpxj.primavera.Primaver...
TargetSite = {java.lang.Double getDuration(net.sf.mpxj.Duration)}
I also tried to manually create a Task and set all fields that seems to be connected with Duration, but still the exception occurs in write
durationUnit = TimeUnit.HOURS;
targetTask.Duration = Duration.getInstance(dDuration, durationUnit);
targetTask.ActualDuration = Duration.getInstance(dDuration, durationUnit);
targetTask.Work = Duration.getInstance(dDuration, durationUnit);
targetTask.DurationVariance = Duration.getInstance(0, durationUnit);
targetTask.DurationText = targetTask.Duration.toString();
targetTask.ActualWork = Duration.getInstance(dDuration, durationUnit);
Which property should be set as well? or maybe the File writer should not crash if any property is null, just take a default value (0) ?
Hi,
can you provide the example XER file you used with your modified version of MpxjConvert so I can try to reproduce the issue?
Thanks
Jon
Hi Jon,
I send you the XER file I tried it with.
But it not depends on the input file, I also tried a different example where I create 1 task and export it, again with Ms Project Writer it works, but with Primavera Writer it crashes because some “Duration” field is not set. Maybe I use the wrong constructor or I need a factory method?
From: Jon Iles [mailto:joniles@users.sf.net]
Sent: Sonntag, 30. August 2015 04:11
To: [mpxj:bugs]
Subject: [mpxj:bugs] #273 PrimaveraPMFileWriter throws Exception at write(..)
Hi,
can you provide the example XER file you used with your modified version of MpxjConvert so I can try to reproduce the issue?
Thanks
Jon
[bugs:#273]http://sourceforge.net/p/mpxj/bugs/273/ PrimaveraPMFileWriter throws Exception at write(..)
Status: open
Group: v1.0_(example)
Labels: Primavera
Created: Wed Aug 26, 2015 02:48 PM UTC by Raimund Neumüller
Last Updated: Wed Aug 26, 2015 02:48 PM UTC
Owner: Jon Iles
Attachments:
PrimaveraPMFileWriter throws exception in getDuration (environment: .NET / Visual Studio 2012)
MPXJ version 5.15
Example: I modified the sample "MpxjConvert"
File created is empty, because in writer.write occurs an exception. it seems that in PrimaveraPMFileWriter.getDuration some object is null:
I also tried to manually create a Task and set all fields that seems to be connected with Duration, but still the exception occurs in write
Which property should be set as well? or maybe the File writer should not crash if any property is null, just take a default value (0) ?
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mpxj/bugs/273/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
Siemens Industry Software GmbH; Sitz der Gesellschaft: Wolfgang-Pauli-Strasse 2, A-4020 Linz, Österreich
Firmenbuchnummer: FN 214676 a; Firmenbuchgericht: Handelsgericht Linz
Related
Bugs:
#273Hello Jon,
here is the sample xer
But it not depends on the input file, I also tried a different example where I create 1 task and export it, again with Ms Project Writer it works, but with Primavera Writer it crashes because some “Duration” field is not set. Maybe I use the wrong constructor or I need a factory method?
Hello Jon,
we tried it out in Java with our example with 1 Task, and my collegue modified PrimaveraPMFileWriter so, that it returns a default value (0.0) if a duration is null. But we don’t know if this always delivers a correct output for Primavera.
With our modification we could generate a primavera xml (see attachment)
PrimaveraPMFileWriter.java
Function getDuration:
/**
*
@return formatted duration
*/
private Double getDuration(Duration duration) {
// kgo add null pointer check
if (duration == null) {
return 0.0;
}
// end kgo
if (duration.getUnits() != TimeUnit.HOURS) {
duration = duration.convertUnits(TimeUnit.HOURS, m_projectFile.getProjectProperties());
}
return Double.valueOf(duration.getDuration());
}
I found out that "RemainingDuration" was the missing value in the task which caused the null pointer exception.. obviously it was not set during the import of my XER file
If I set something in RemainingDuration, for example:
.NET : targetTask.RemainingDuration = targetTask.Work;
Java: targetTask.setRemainingDuration(targetTask.getDuration());
then the Primavera Writer runs through and export works
Maybe there should be a default value set for RemainingDuration?
This issue is fixed by the code now in git.