when enter the listeyidoldur() method , second try catch is running.catch is runing.open the "hata" message. Maps is running,but when remove second try-catch , i get "application has stopped" error. Can you help me?
import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import java.io.BufferedInputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{ private GoogleMap myMap; ListView liste; public static final LatLng PERTH = new LatLng(36.57, 36.17); private FragmentManager childFragmentManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); getHandleOnMap(); liste=(ListView)findViewById(R.id.listView); listeyidoldur(); } private void listeyidoldur() { StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); String xml_url="http://www.bilisimzade.net/mekan.xml"; List<String> mekan_liste=new ArrayList<>(); HttpURLConnection baglanti=null; try{ URL url=new URL(xml_url); baglanti=(HttpURLConnection) url.openConnection(); int baglanti_durum=baglanti.getResponseCode(); if(baglanti_durum==HttpURLConnection.HTTP_OK){ BufferedInputStream stream=new BufferedInputStream(baglanti.getInputStream()); DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); Document document=documentBuilder.parse(stream); NodeList mekan_dugum=document.getElementsByTagName("mekan"); for(int i=0;i<mekan_dugum.getLength();i++){ Element element=(Element)mekan_dugum.item(i); NodeList nodeListisim=element.getElementsByTagName("isim"); NodeList nodeykor=element.getElementsByTagName("ykor"); NodeList nodexkor=element.getElementsByTagName("xkor"); NodeList nodetel=element.getElementsByTagName("tel"); NodeList nodeadres=element.getElementsByTagName("adres"); String isim=nodeListisim.item(0).getFirstChild().getNodeValue(); String ykor=nodeykor.item(0).getFirstChild().getNodeValue(); String xkor=nodexkor.item(0).getFirstChild().getNodeValue(); String tel=nodetel.item(0).getFirstChild().getNodeValue(); String adres=nodeadres.item(0).getFirstChild().getNodeValue(); mekan_liste.add(isim +"adlı şirketin koordinatları"+ykor+","+xkor+" "+tel ); } } }catch (Exception ex){ Log.e("xml parse hatası" , ex.getMessage().toString()); }finally { if (baglanti!=null){ baglanti.disconnect(); } } try { ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, mekan_liste); liste.setAdapter(adapter); }catch (Exception ex){ Toast.makeText(getApplicationContext(),"Hata",Toast.LENGTH_SHORT).show(); } } private void getHandleOnMap() { SupportMapFragment mapFragment = (SupportMapFragment) this.getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap myMap) { Marker marker= myMap.addMarker(new MarkerOptions() .position(PERTH) ); myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(36.58271, 36.1664039), 12)); myMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){ @Override public View getInfoWindow(Marker marker) { View v=getLayoutInflater().inflate(R.layout.infowindows,null); return v; } @Override public View getInfoContents(Marker marker) { return null; } }); } }
No comments:
Post a Comment