Casting node to element giving ClassCastException

前端 未结 2 1666
慢半拍i
慢半拍i 2020-12-21 00:02

here n2 is my NodeList, and i just want to see the first child node of my root element

public void ClickMe(View view){


    Node rootElement=n2.item(0);         


        
2条回答
  •  轮回少年
    2020-12-21 00:59

    If node is element then only cast it. Make check like below.

    if (first.getNodeType() == Node.ELEMENT_NODE) { Element nm=(Element)first;}
    

提交回复
热议问题