Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm getting the following exception.

Caused by:

java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Integer

with the following code

List queryResult = query.list();

for (Iterator<Object[]> it = queryResult.iterator(); it.hasNext();) {
    Object[] result = it.next();
    Integer childId = (Integer) result[0];
    Integer grandChildCount = (Integer) result[1];
    CompanyNode childNode = childNodes.get(childId);
    childNode.setHasChildren(grandChildCount != 0);
    childNode.setIsLeaf(grandChildCount == 0);
}

at this line

Integer grandChildCount = (Integer) result[1];

Does anybody have any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
754 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use:

Integer grandChildCount = ((BigInteger) result[1]).intValue();

Or perhaps cast to Number to cover both Integer and BigInteger values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...