我使用SDK 12得到此错误。
Caused by: org.apache.xml.serializer.utils.WrappedRuntimeException: Could not load the propery file 'output_xml.properties' for output method 'xml' (check CLASSPATH)
活动中的第175行是Transformer trans = transfac.newTransformer();
。
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): FATAL EXCEPTION: AsyncTask #1
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): java.lang.RuntimeException: An error occured while executing doInBackground()
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at android.os.AsyncTask$3.done(AsyncTask.java:266)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.lang.Thread.run(Thread.java:1020)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): Caused by: org.apache.xml.serializer.utils.WrappedRuntimeException: Could not load the propery file 'output_xml.properties' for output method 'xml' (check CLASSPATH)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties(OutputPropertiesFactory.java:322)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at org.apache.xalan.templates.OutputProperties.<init>(OutputProperties.java:83)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at org.apache.xalan.transformer.TransformerIdentityImpl.<init>(TransformerIdentityImpl.java:88)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:823)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at jpl.test.AndroidserverActivity.generateXML(AndroidserverActivity.java:175)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at jpl.test.AndroidserverActivity$GetXML.doInBackground(AndroidserverActivity.java:63)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at jpl.test.AndroidserverActivity$GetXML.doInBackground(AndroidserverActivity.java:1)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at android.os.AsyncTask$2.call(AsyncTask.java:252)
07-18 10:32:41.695: ERROR/AndroidRuntime(12864): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
下面是我的代码:
public class AndroidserverActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GetXML xml = new GetXML();
xml.execute();
}
private class GetXML extends AsyncTask<String, Integer, String>
{
protected String doInBackground(String... conn)
{
String UID = "iPAD-CN5-DSS25-AC25";
try
{
String xml = generateXML("AC25", "/fa/gdscc/dss25-apc", UID);
if (send("localhost", xml))
getData(UID);
else
System.out.println("False");
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
public static String generateXML(String conn, String funcAddr, String UID) throws ParserConfigurationException, SAXException,
IOException, XPathExpressionException, TransformerException
{
String url = getXML("0", conn);
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = XMLfromString(url);
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("/SubscrProf/DataItem/DataItemName");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
//build xml
Document output = builder.newDocument();
//create root
org.w3c.dom.Element root = output.createElement("JMSMON2Req");
output.appendChild(root);
//create subitem
org.w3c.dom.Element subItemNode = output.createElement("SubItem");
subItemNode.setAttribute("UID", UID);
root.appendChild(subItemNode);
//create funcAddr
org.w3c.dom.Element funcAddrNode = output.createElement("FuncAddr");
Text text = output.createTextNode(funcAddr);
funcAddrNode.appendChild(text);
subItemNode.appendChild(funcAddrNode);
//create itemname
for (int i = 0; i < nodes.getLength(); i++)
{
org.w3c.dom.Element itemNameNode = output.createElement("ItemName");
text = output.createTextNode(nodes.item(i).getTextContent());
itemNameNode.appendChild(text);
subItemNode.appendChild(itemNameNode);
}
//create metadata uid
org.w3c.dom.Element metaDataNode = output.createElement("Metadata");
metaDataNode.setAttribute("key", "UID");
text = output.createTextNode(UID);
metaDataNode.appendChild(text);
subItemNode.appendChild(metaDataNode);
//create metadata conn
org.w3c.dom.Element metaDataNode2 = output.createElement("Metadata");
metaDataNode2.setAttribute("key", "CONN");
text = output.createTextNode("5");
metaDataNode2.appendChild(text);
subItemNode.appendChild(metaDataNode2);
/////////////////
//Output the XML
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult out = new StreamResult(sw);
DOMSource source = new DOMSource(output);
trans.transform(source, out);
return URLEncoder.encode("req", "UTF-8") + "=" + URLEncoder.encode(sw.toString(), "UTF-8");
}
尝试在调用xml.execute()时发送一个字符串参数;