how to resolve java.lang.string cannot be cast to java.lang.integer android with xml parser

前端 未结 2 2022
温柔的废话
温柔的废话 2021-01-14 18:52

I am trying to parse XML and display it into list view, but after running the app nothing happens -- the list is displayed but not with the XML data . I don\'t know if I am

相关标签:
2条回答
  • 2021-01-14 19:27

    If you have a String and you are sure that the only thing in it is a whole number without spaces, you can use Integer.parseInt(String) to convert it to an integer. This method will throw an exception if the string isn't just the number.

    0 讨论(0)
  • 2021-01-14 19:28

    You cannot directly change or reference your String object to Integer type because there is no parent-child relationship between these two classes.

    If you try to cast a String to a Integer in such a way, it will raise a ClassCastException.

    String someValue = "123";
    Integer intValue = (Integer) someValue; // ClassCastException Raise.
    

    So if you want to change or reference a String Variable to Integer, you must use parsing techniques.

    int intValue = Integer.parseInt(someValue); //this code will work for this.
    
    0 讨论(0)
提交回复
热议问题