0

Possible Duplicate:
Android internet connectivity check problem

I have an application that uses internet, this works fine when I have internet connection, but when I haven't internet, this application is closed.

my code is:

  import java.net.URL;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Xml;
import android.view.KeyEvent;
import android.widget.TextView;

    public class xml75 extends Activity {

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.sietemildoss);

            TextView tv = (TextView) findViewById(R.id.tv);

            try {
                URL url = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=75");
                ExampleHandler75 myExampleHandler = new ExampleHandler75();
                Xml.parse(url.openStream(), Xml.Encoding.UTF_8, myExampleHandler);

                List<ParsedExampleDataSet> parsedExampleDataSetList = 
                        myExampleHandler.getParsedData();

                for(ParsedExampleDataSet parsedExampleDataSet : parsedExampleDataSetList){
                    tv.append(parsedExampleDataSet.toString4());

                }

            } catch(Exception e){
                tv.setText("Error:" + e.getMessage());
            }

        }
Community
  • 1
  • 1
edwin rojas
  • 139
  • 2
  • 9
  • 1
    You need to show a bit more of your code or the error stacktrace but it seems to me that it could have something to do with your list "parsedExampleDataSetList". Could it be that you use this variable further in your code and the app crashes with a NullPointerException? Cheers – Jose L Ugia Sep 25 '12 at 18:19
  • so what's the issue you need to check the connection first and place a if condition for the code to be executed only if net is available – Arpit Garg Sep 25 '12 at 18:20
  • yes. either check the connection first or check your parse if it is null, which it will be when there is no connection. that is why your app is crashing! – SunnySonic Sep 25 '12 at 18:40
  • @edwinrojas If you've fixed it, post the solution as an answer and accept it. – Raghav Sood Sep 25 '12 at 19:05

0 Answers0