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