0
Hello,

I am using Java API to Create Item. But getting Null Pointer Exception while executing.
Here is what I have done.

DimensionsConnectionDetails details = new DimensionsConnectionDetails();
details.setUsername("*");
details.setPassword("*");
details.setDbName("*");
details.setDbConn("*");
details.setServer("*");
DimensionsConnection connection = DimensionsConnectionManager.getConnection(details);
DimensionsObjectFactory factory = connection.getObjectFactory();
Project gProject = factory.getProject("EDS_BARS:_WORK_MAIN");
ItemRevisionDetails ird = new ItemRevisionDetails();
ird.setUserFileName("C:\\PVCS\\G180\\TEST\\E_PED\\EDS_BARS_G180_TR_15.zip");
ird.setProjectFileName("EDS_BARS_G180_TR_15.zip");
ird.setProductName(gProject.getName());
//ird.setType();
ird.setTypeName("CM4");
ird.setRevision("1.0");
ird.setVariant("A");
ird.setOwningPartSpecification("EDS_BARS:G180_TEST_E_PED.A;1");
ird.setFormat("ZIP");
ird.setComment("Via PVCS API");
try {
factory.createItem(ird,gProject,true);
} catch (DimensionsRuntimeException e) {
System.err.println("Failed to create request.");
System.err.println(e.getMessage());
}

I feel there is a problem with the commented line of code //ird.setType() . But in the next steps am setting the type name and format as well.

Can you confirm if the issue is in the commented line? If yes how to set the Type?

This is the stack trace of the exception

Exception in thread "main" java.lang.NullPointerException
at merant.adm.dimensions.cmds.AdmCmd.getCmd(AdmCmd.java:196)
at com.serena.dmclient.impl.helpers.AdmGetter.queryChild(AdmGetter.java:1180)
at com.serena.dmclient.impl.helpers.AdmGetter.getTypeById(AdmGetter.java:1040)
at com.serena.dmclient.api.DimensionsObjectFactoryImpl.createItemRevisionInternal(DimensionsObjectFactoryImpl.java:1128)
at com.serena.dmclient.api.DimensionsObjectFactoryImpl.createItem(DimensionsObjectFactoryImpl.java:1010)
at com.serena.dmclient.api.DimensionsObjectFactoryImpl.createItem(DimensionsObjectFactoryImpl.java:977)
at com.bosch.honeywell.pvcs.CreatePVCS.main(CreatePVCS.java:44)


Regards,
Vineet
Responses (1)
  • Accepted Answer

    Wednesday, October 05 2016, 09:13 AM - #Permalink
    0
    Hi Vineet, the following line looks suspicious to me as it is setting the Product name based on the Project name.
    ird.setProductName(gProject.getName());

    Regardless, I recommend checking each value returned from the calls and avoid passing function results directly into other function calls to give you opportunity to inspect the results before they are used. Try to validate all values before the createItem call.
    The reply is currently minimized Show
Your Reply