当前位置: 代码迷 >> Eclipse >> "Unreachable code"是什么东东
  详细解决方案

"Unreachable code"是什么东东

热度:134   发布时间:2016-04-23 18:44:33.0
"Unreachable code"是什么错误?
我在使用Eclipse写Java代码时报了这个错误,请明白人告知一下这个错误该如何解释?谢谢

以下是具体的程序代码:
package   domprinter;

import   java.io.*;
import   javax.xml.parsers.*;
import   org.w3c.dom.*;
import   org.xml.sax.*;

public   class   DOMPrinter  
{
/*
  *   输出节点的名字和节点的值
  */
public   static   void   printNodeInfo(Node   node)
{
System.out.println(node.getNodeName()   +   "   :   "   +   node.getNodeValue());
}
/*
  *   采用递归调用,输出指定节点下的所有后代节点
  */
public   static   void   printNode(Node   node)
{
short   nodeType   =   node.getNodeType();
switch(nodeType)
{
case   Node.PROCESSING_INSTRUCTION_NODE:
System.out.println( "*****PI   start***** ");
printNodeInfo(node);
System.out.println( "*****PI   end***** ");
break;
case   Node.ELEMENT_NODE:
System.out.println( "*****ELEMENT   start***** ");
printNodeInfo(node);
System.out.println( "*****ELEMENT   end****** ");
break;

NamedNodeMap   attrs   =   node.getAttributes();
int   attrNum   =   attrs.getLength();
for(int   i=0;i <attrNum;i++)
{
Node   attr   =   attrs.item(i);
System.out.println( "*****Attribute   start***** ");
printNodeInfo(attr);
System.out.println( "*****Attribute   end***** ");
}
break;

case   Node.TEXT_NODE:
System.out.println( "*****Text   start***** ");
printNodeInfo(node);
System.out.println( "*****Text   end***** ");
break;
default:
break;
}

Node   child   =   node.getFirstChild();
while(child   !=   null)
{
printNodeInfo(child);
child   =   child.getNextSibling();
}
}
public   static   void   main(String[]   args)
{
DocumentBuilderFactory   dbf   =   DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder   db   =   dbf.newDocumentBuilder();
Document   doc   =   db.parse(new   File( "students.xml "));
printNode(doc);
}
catch(ParserConfigurationException   e){e.printStackTrace();}
catch(SAXException   e){e.printStackTrace();}
catch(IOException   e){e.printStackTrace();}
}
}

students.xml:

<?xml   version= "1.0 "   encoding= "gb2312 "?>
<?xml-stylesheet   type= "text/xml "   href= "students.xml "?>
<!DOCTYPE   students   [
<!ELEMENT   students   (student*)>
<!ELEMENT   student   (name,age)>
<!ELEMENT   name   (#PCDATA)>
<!ELEMENT   age   (#PCDATA)>
]>

<students>
<student   sn= "01 ">
<name> 张三   </name>
<age> 18   </age>
</student>

<student   sn= "02 ">
<name> 李四   </name>
<age> 20   </age>
</student>
</students>

------解决方案--------------------
  相关解决方案