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 ";
}
}
L'appel de cette fonction via Runnable, Got exception android.os.NetworkOnMainThreadException je pourrais changer le lien pour http://in2streaming.com:9999/7.html et utiliser l'analyseur HTML au lieuErreur dans l'obtention XML et l'analyser
// 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);
}
};
Quelle est l'erreur? poster le logcat – pleft
java.lang.NullPointerException: Tentative d'invocation de la méthode virtuelle 'void android.app.NotificationManager.createNotificationChannel (android.app.NotificationChannel)' sur une référence d'objet nul at cloud.SmoothRadio.nagare.MainJava.showNotification (MainJava .java: 60) à cloud.SmoothRadio.nagare.MainJava.onClick (MainJava.java:120) –
Cette erreur n'appartient pas au code source affiché dans la question. – pleft