p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android 4 Application Development (http://p2p.wrox.com/forumdisplay.php?f=685)
-   -   Chapter 6 Earthquake Viewer (http://p2p.wrox.com/showthread.php?t=98686)

StefanieD March 4th, 2016 10:44 PM

Chapter 6 Earthquake Viewer
 
I have entered all the code for the Chapter 6 Earthquake Viewer app only to discover the http://earthquake.usgs.gov/eqcenter/.../1day-M2.5.xml for the string resource value is no longer valid. I've looked at the posts in this forum and another link was listed, but it no longer works either. Has anyone completed this app lately who has found the right URL for the string resource? This is a class assignment and it is due Sunday.

Kees March 5th, 2016 07:23 AM

Chapter 6 Earthquake Viewer
 
Hi, yes things have changed ...
look at http://earthquake.usgs.gov/earthquak...v1.0/index.php
Look at atom syndication.
In stead of that 1 day M2.5.xml use http://earthquake.usgs.gov/earthquak...y/2.5_day.atom
for instance.
The use of the atom files is preferrable rather than the quakeml's, as they contain the entry and title tags and more that are expected in the chapter 6 example.

StefanieD March 5th, 2016 10:02 AM

Chapter 6 not working
 
I tried that and it still didn't work. I even tried it using the source code in case I typed it in wrong from the book.

Kees March 5th, 2016 10:29 AM

Chapter 6 not working
 
Try to debug into refreshEarthquakes, if you arrive in the for loop after
NodeList nl = docEle .... Then you can step through.
Such i did some years ago after not seeing any list, and it helped. Well, there is always a reason why it doesnt work [:)]

Kees March 5th, 2016 11:05 AM

Chapter 6 not working
 
Hi Stephanie,
I remember a problem with the code of chapter 6 (no list at all)

In 2013 i found this exception in logcat :

"android.view.ViewRoot$CalledFromWrongThreadEx cept ion: Only the original thread that created a view hierarchy can touch its views"
If so, then it is likely due to calling aa.notifyDataSetChanged() in earthquakeListfragment.java from the thread that started refreshEarthquakes().
So the code in the book with the thread does not (always) work!!

You could try the chapter 9 example, where EarthquakeUpdateService is used.
Good luck!

StefanieD March 5th, 2016 06:45 PM

Works in Android Studio, sort of...
 
I imported my Eclipse project into Android Studio just to see what happens and, surprise, I got a list of Earthquakes. However, I get 00:00 for all the times. I am not familiar with Android Studio since in class we are using Eclipse Luna, so I have no idea how to fix the time issue. I still can't get the program to list the data in Eclipse.

StefanieD March 5th, 2016 07:24 PM

Date parsing exception
 
Okay, I went back through the forum threads and found a fix for the time issue, but now I see I am getting a date parsing exception. The zeros for the time distracted me from the fact I have no dates either.

Kees March 6th, 2016 06:55 AM

Date parsing exception
 
It surprises me that Android Studio does not raise that wrongthreadexception, i didnt try to run the same in studio.

Okay, i know what could cause the parsing error (if you didnt change the string in the line with simpledateformat).
Because the date string in the feed files now is for instance :
"2015-12-19T11:31:38.991Z",
so for all entries "yyyy-MM-dd'T'hh:mm:ss'.'SSS'Z'"
If you change that in the code :
SimpleDateFormat sdf =
new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'.'SSS'Z'",
Locale.getDefault());

Hope this helps to read the dates!

StefanieD March 6th, 2016 03:16 PM

Date issue resolved
 
Actually, after I thought about it a little more, I went back and looked a little closer and found a typo in the date format. After I fixed that and ran the debugger again, I could see the dates listed each time the program went through the loop, but they still weren't showing on the device. So I thought, maybe they aren't showing up because I wasn't asking them to. I took a look at my Quake.java and, sure enough, I had entered the book code and all it asks for is the time.

In Quake.java the book only lists:

sdf = new SimpleDateFormat("hh:mm");

So you only get the hour and minute values. I changed the code to:

Public String toString() {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd, hh:mm");

String dateString = sdf.format(date);

return dateString + ": " + "M " + magnitude + ", " + details;

}

Now I have the date as well as the time in my listing.

I still can't get the program to give me the listing in Eclipse.

StefanieD March 6th, 2016 05:07 PM

Eclipse debugger results
 
In Eclipse, when I run it through the debugger, I am not getting past checking to see if the http connection is okay. I'm getting a file not found error.

if(response code == HttpURLConnection.HTTP_OK) {

I get name: responseCode, value: 404

It's driving me nuts that the same URL working in Android Studio, but won't work in Eclipse.


All times are GMT -4. The time now is 06:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.