cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Bug while using QueryResult

atemnikov
7-Bedrock

Bug while using QueryResult

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.

ACCEPTED SOLUTION

Accepted Solutions
imendiola
13-Aquamarine
(To:atemnikov)

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

http://www.prambanan-it.comIker Mendiola - Prambanan IT Services

View solution in original post

4 REPLIES 4
imendiola
13-Aquamarine
(To:atemnikov)

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

http://www.prambanan-it.comIker 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

imendiola
13-Aquamarine
(To:atemnikov)

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

http://www.prambanan-it.comIker Mendiola - Prambanan IT Services

Hi Iker,

It seems I really forgotten to restart MethodServer. Now this code works. Thank you!

Best regards

Announcements


Top Tags