Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hello,
I have got strange exception while using wt.fc.QueryResult class. In code below it returns type [Lwt.fc.Persistable; (with symbols) instead wt.fc.Persistable
protected void collectEntrance() {
try {
QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());
while (qr.hasMoreElements()) {
WTPart nextPart = (WTPart) qr.nextElement();
//TODO:remove with specification element
switch (nextPart.getPartType().toString()) {
case "separable":
structure.add(new Assembly(nextPart, part));
break;
case "detail":
structure.add(new Detail(nextPart, part));
break;
}
}
} catch (WTException e) {
e.printStackTrace();
}
}
What should I do?
Thanks.
Solved! Go to Solution.
Hi Andrey,
if your log is giving the same error than the first time, and in the same line number (79)... Try restarting the MethodServer if you have not done.
The cast exception is because you were trying to cast a Persistable array (Persistable[]) to a Persistable object. And the method you are using (WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec()) returns a QueryResult of Persistable[]
Just to be sure, your method should look like this:
protected void collectEntrance() {
try {
QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());
while (qr.hasMoreElements()) {
// WTPart nextPart = (WTPart) qr.nextElement();
Persistable aPersistable[] = (Persistable[]) qr.nextElement();
WTPart nextPart = (WTPart) aPersistable[1];
//TODO:remove with specification element
switch (nextPart.getPartType().toString()) {
case "separable":
structure.add(new Assembly(nextPart, part));
break;
case "detail":
structure.add(new Detail(nextPart, part));
break;
}
}
} catch (WTException e) {
e.printStackTrace();
}
}
If it continues giving an error, check the line number where the error is thrown in the log.
ava.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable
at ru.windchill.versioncontrolreport.details.Element.collectEntrance(Element.java:79)
at ru.windchill.versioncontrolreport.details.Element.<init>(Element.java:42)
Regards
Iker Mendiola - Prambanan IT Services |
Hi Andrey,
try with this:
while (qr.hasMoreElements()) {
Persistable aPersistable[] = (Persistable[]) qr.nextElement();
WTPart nextPart = (WTPart) aPersistable[1];
}
If I remember well, I think that position 0 of the array contains the UsageLink and position 1 contains the child WTPart.
Regards
Iker Mendiola - Prambanan IT Services |
Hi, Iker
I have tried to do as you said, but again caught exception java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable
I think, problem is in using of reflective methods, but I cannot trace it. There is part of log:
java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable
...my methods...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at wt.httpgw.HTTPServletResponse.invoke(HTTPServletResponse.java:251)
...others...
May it be any problems with installing or settings of Windchill?
Regards
Hi Andrey,
if your log is giving the same error than the first time, and in the same line number (79)... Try restarting the MethodServer if you have not done.
The cast exception is because you were trying to cast a Persistable array (Persistable[]) to a Persistable object. And the method you are using (WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec()) returns a QueryResult of Persistable[]
Just to be sure, your method should look like this:
protected void collectEntrance() {
try {
QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());
while (qr.hasMoreElements()) {
// WTPart nextPart = (WTPart) qr.nextElement();
Persistable aPersistable[] = (Persistable[]) qr.nextElement();
WTPart nextPart = (WTPart) aPersistable[1];
//TODO:remove with specification element
switch (nextPart.getPartType().toString()) {
case "separable":
structure.add(new Assembly(nextPart, part));
break;
case "detail":
structure.add(new Detail(nextPart, part));
break;
}
}
} catch (WTException e) {
e.printStackTrace();
}
}
If it continues giving an error, check the line number where the error is thrown in the log.
ava.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable
at ru.windchill.versioncontrolreport.details.Element.collectEntrance(Element.java:79)
at ru.windchill.versioncontrolreport.details.Element.<init>(Element.java:42)
Regards
Iker Mendiola - Prambanan IT Services |
Hi Iker,
It seems I really forgotten to restart MethodServer. Now this code works. Thank you!
Best regards