I have a problem to get .xml data from website and parse to android application, i have try many suggestion but never work. It works fine when i open file in assets folder, but when i try to get from url, it show nothing
This is my Activity Class
package com.android.baliweather;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
public class Prakiraan extends Activity {
/** Called when the activity is first created. */
private ListView listView;
private TextView judul;
private String URL_MAIN = "http://localhost/android/propinsi_17_1.xml";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prakiraan_cuaca);
judul = (TextView) findViewById(R.id.menu1);
listView = (ListView) findViewById(R.id.listview);
bindDataToListing();
}
private void bindDataToListing() {
try {
URL url = new URL("http://localhost/android/propinsi_17_1.xml");
URLConnection connection = url.openConnection();
//URLConnection connection = url.openConnection();
//HttpURLConnection httpConnection = (HttpURLConnection)connection;
//InputStream in = httpConnection.getInputStream();
SAXParserFactory saxparser = SAXParserFactory.newInstance();
SAXParser parser = saxparser.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
XMLParser pc = new XMLParser();
xmlReader.setContentHandler(pc);
//InputStream is = getAssets().open("propinsi_17_1.xml");
//InputStream is = new URL(URL_MAIN).openStream();
xmlReader.parse(new InputSource(connection.getInputStream()));
BindingData bindingData = new BindingData(this, pc.kota, pc.cuaca, pc.suhuMin, pc.suhuMax, pc.kelembapanMin, pc.kelembapanMax, pc.kecepatanAngin, pc.arahAngin);
listView.setAdapter(bindingData);
}
catch (Exception e) {
e.getMessage();
}
}
}
I think the problem only on this class, but i have no idea which one. Please help