public String getMetaData() {
String errors = "";
try {
URL url = new URL("http://in2streaming.com:9999/stats?sid=1.xml");
URLConnection conn = url.openConnection();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Error Here:
Document doc = db.parse(conn.getInputStream().toString());
// get the root node
NodeList nodeList = doc.getElementsByTagName("SHOUTCASTSERVER");
Node node=nodeList.item(0);
// the node has three child nodes
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node temp=node.getChildNodes().item(i);
if(temp.getNodeName().equalsIgnoreCase("SONGTITLE")){
return temp.getTextContent();
}
}
return "Couldn't reach XML";
}
catch (Exception e) {
return "Exception ";
}
}
通過調用Runnable接口,拿到了異常這一功能android.os.NetworkOnMainThreadException 我可能鏈接更改爲http://in2streaming.com:9999/7.html和使用HTML解析器,而不是錯誤中獲取XML和解析它
// Refresh meta data
private final Runnable refresh_meta = new Runnable() {
@Override
public void run() {
Toast.makeText(m_context, getMetaData(), Toast.LENGTH_SHORT).show();
m_handler.postDelayed(this, 5000);
}
};
有什麼錯誤?發佈logcat – pleft
java.lang.NullPointerException:試圖調用虛擬方法'void android.app.NotificationManager.createNotificationChannel(android.app.NotificationChannel)'在空對象引用 at cloud.SmoothRadio.nagare.MainJava.showNotification(MainJava .java:60) at cloud.SmoothRadio.nagare.MainJava.onClick(MainJava.java:120) –
此錯誤不屬於發佈在問題中的源代碼。 – pleft