The sixth chapter, an issue of using Internet resources

Source: Internet
Author: User

The example code in the sixth chapter today is not working. Prompt for objects that are not referenced.

Append Code Snippet

private void Refreshearthquakes () {
Get the XML
URL url;
try {
String quakefeed = getString (r.string.quake_feed);
url = new URL (quakefeed);

URLConnection connection;
Connection = Url.openconnection ();

HttpURLConnection httpconnection = (httpurlconnection) connection;
int responsecode = Httpconnection.getresponsecode ();

if (Responsecode = = HTTPURLCONNECTION.HTTP_OK) {
InputStream in = Httpconnection.getinputstream ();

Documentbuilderfactory dbf = Documentbuilderfactory.newinstance ();
Documentbuilder db = Dbf.newdocumentbuilder ();

Parse the earthquake feed.
Document dom = Db.parse (in);
Element Docele = Dom.getdocumentelement ();

Clear the old earthquakes
Earthquakes.clear ();

Get A list of each earthquake entry.
NodeList nl = docele.getelementsbytagname ("entry");
if (nl! = null && nl.getlength () > 0) {

     //The i=0 here is changed to I=1.
for (int i = 1; i < nl.getlength (); i++) {
Element entry = (element) nl.item (i);
Element title = (Element) entry.getelementsbytagname ("title"). Item (0);

Element g = (Element) entry.getelementsbytagname ("Georss:point"). Item (0);
Element g = (Element) Entry.getelementsbytagname ("Summary"). Item (0);

element when = (element) Entry.getelementsbytagname ("updated"). Item (0);
Element link = (Element) entry.getelementsbytagname ("link"). Item (0);

String details = Title.getfirstchild (). Getnodevalue ();
String hostname = "http://earthquake.usgs.gov";
String linkstring = hostname + link.getattribute ("href");

String point = G.getfirstchild (). Getnodevalue ();
String dt = When.getfirstchild (). Getnodevalue ();
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd ' T ' hh:mm:ss ' Z ');
Date qdate = new GregorianCalendar (0,0,0). GetTime ();
try {
Qdate = sdf.parse (DT);
} catch (ParseException e) {
LOG.D (TAG, "Date parsing exception.", E);
}

string[] location = Point.split ("");
Location L = new location ("Dummygps");
L.setlatitude (Double.parsedouble (location[0));
L.setlongitude (Double.parsedouble (location[1));

String magnitudestring = Details.split ("") [1];
int end = Magnitudestring.length ()-1;
Double magnitude = double.parsedouble (magnitudestring.substring (0, end));

Details = Details.split (",") [1].trim ();

Quake Quake = new Quake (qdate, details, l, magnitude, linkstring);

Process a newly found earthquake
Addnewquake (Quake);
}
}
}
} catch (Malformedurlexception e) {
LOG.D (TAG, "Malformedurlexception", e);
} catch (IOException e) {
LOG.D (TAG, "IOException", e);
} catch (Parserconfigurationexception e) {
LOG.D (TAG, "Parser Configuration Exception", e);
} catch (Saxexception e) {
LOG.D (TAG, "SAX Exception", e);
}
finally {
}
}
On the page to view the time, found that the No. 0 earthquake situation is not. So I can't find it.

This is true of the entire sample code, it's sad.

The sixth chapter, an issue of using Internet resources

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.