【问题标题】:In Android, how do I view the error that was received in the try/catch block?在 Android 中,如何查看在 try/catch 块中收到的错误?
【发布时间】:2011-01-16 01:51:32
【问题描述】:
  public static void parseit(String thexml){
         SAXParserFactory factory = SAXParserFactory.newInstance();
         SAXParser saxParser;

        try {
            saxParser = factory.newSAXParser();
            DefaultHandler handler = new DefaultHandler() {
                public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {


                }
                public void endElement(String uri, String localName, String qName)throws SAXException {

                }

                public void characters(char ch[], int start, int length) throws SAXException {

                }


             };      
            saxParser.parse(thexml, handler);
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }catch (ParserConfigurationException e) {
                e.printStackTrace();    
            }
        }

这是我解析 XML 文档的代码。但是,它总是进入 IOException e,我不知道为什么。有人可以告诉我如何查看该错误吗?

LogCat?但是我该如何记录呢?

【问题讨论】:

    标签: java android debugging exception try-catch


    【解决方案1】:

    而不是e.printStackTrace(),使用Log.e(....,....,e);

    然后使用logcat观看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-27
      • 2020-12-30
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多