Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 4 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 28th, 2013, 01:14 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
Exclamation Chapter 6 - Earthquake App Example

For those of you who really try the examples in the book:
In chapter 6 you are shown an example of an app handling with XML data from an earthquake logging website. The Link to the website is deprecated and not available anymore that means your httprequests will result in a "404 Not Found" failure.
If you want to try out the example use the following link: http://earthquake.usgs.gov/earthquak...y/2.5_day.atom
This is the updated site.

Further on much fun with your book.

Greets Christopher.
Reply With Quote
The Following 2 Users Say Thank You to ChristopherReichel For This Useful Post:
wolfenr (November 13th, 2014)
  #2 (permalink)  
Old November 26th, 2013, 01:04 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

with the updated url it still got same crash:

11-26 11:51:54.478: E/AndroidRuntime(16764): FATAL EXCEPTION: main
11-26 11:51:54.478: E/AndroidRuntime(16764): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.earthquake/com.paad.earthquake.Earthquake}: android.os.NetworkOnMainThreadException
Reply With Quote
  #3 (permalink)  
Old November 26th, 2013, 01:50 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Different problem. Try running the network code on a separate thread.
Reply With Quote
  #4 (permalink)  
Old November 26th, 2013, 08:38 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just got the book. Thought it should be up to date. Wondering if any of the book editor cares about it.
Reply With Quote
  #5 (permalink)  
Old November 26th, 2013, 08:57 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by lanny View Post
Just got the book. Thought it should be up to date. Wondering if any of the book editor cares about it.
I was the tech editor. Maybe I missed something. Could you tell me where it's not explained in the book? I think page 209, step 10 has the correct code.
Reply With Quote
  #6 (permalink)  
Old November 26th, 2013, 09:49 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the response and good to know someone does care about the feedback. I was running the sample before start to read the chapter just for to know what it is going to talk about. I will try to replace the code with what is in the book to see how it goes. Thanks again!
If the downloaded code match the book it would be better.
Reply With Quote
  #7 (permalink)  
Old November 26th, 2013, 10:09 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I do care about feedback. The quality of the book is important to me and I hope the feedback can help make the next edition better. Unfortunately, I think there may have been a difference between the downloaded code and what is in the book (I think the book is correct). I don't handle uploading the code samples, but I did let Reto know about it awhile back.

If I recall, API level 11 had just been released not long before we finished the book and this exception was one of those things that was introduced. I think prior to that, the exception doesn't get thrown, so the downloaded version should work in that situation, although it still is bad form.
Reply With Quote
  #8 (permalink)  
Old November 29th, 2013, 07:28 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi!
Great to see that there is actually a reply on this subject. I'm currently struggling with the EXACT same issue.

I have tried two approaches:
1) Importing the code sample and adding
Code:
<uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="11" />
to the manifest, as well as changing
Code:
refreshEarthquakes();
to the version in the book (with the thread). However, this results in the following error:
Quote:
[Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
[Chapter_6_Earthquake] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.


I tried googling the error and it was suggested to change the project.properties file so it matches the target (11 in this case). However, this didn't help.

2) I've tried manually creating the program (actually did this first) and followed the book. Since my usual targetSDK is 19, I encountered the error mentioned here in the thread and in the book. But again, changing minSdkVersion and targetSdkVersion to 11 didn't help either. At least here I get to the point where it tried to install the program on my AVD, but the application crashes ("Unfortunately, Earthquake has stopped") and I get plenty of error messages:
Quote:
E/AndroidRuntime(519): FATAL EXCEPTION: Thread-69
E/AndroidRuntime(519): android.view.ViewRootImpl$CalledFromWrongThreadExc eption: Only the original thread that created a view hierarchy can touch its views.
E/AndroidRuntime(519): at android.view.ViewRootImpl.checkThread(ViewRootImpl .java:4039)
...
To be honest, I'm quite new to Java as well and I really struggle when encountering errors (since I don't know where to go to fix them).

So any help on this subject would be greatly appreciated, as this project (and understanding these issues) seems rather important when going forward.


Edit:While I was unable to fix the Earthquake example, I did get the same error (Dex Loader...) in a later example (Chapter_12_GForceMeter). There, changing the targetSdkVersion in the manifest and target in the project.properties did allow me to run the app successfully. So changing Earthquake to 19 in the manifest and project.properties results in a different error, though I'm not sure that this is due to the network issue... :
Quote:
E/AndroidRuntime(1476): FATAL EXCEPTION: Thread-102
E/AndroidRuntime(1476): Process: com.paad.earthquake, PID: 1476
E/AndroidRuntime(1476): java.lang.NullPointerException
E/AndroidRuntime(1476): at com.paad.earthquake.EarthquakeListFragment.refresh Earthquakes(EarthquakeListFragment.java:95)
E/AndroidRuntime(1476): at com.paad.earthquake.EarthquakeListFragment.access$ 0(EarthquakeListFragment.java:55)
E/AndroidRuntime(1476): at com.paad.earthquake.EarthquakeListFragment$1.run(E arthquakeListFragment.java:47)
E/AndroidRuntime(1476): at java.lang.Thread.run(Thread.java:841)
EarthquakeListFragment.java:47 is the refreshEarthquakes() inside the Thread t, btw. Consider me thoroughly confused.

Last edited by Markstar; November 29th, 2013 at 08:17 AM.
Reply With Quote
  #9 (permalink)  
Old November 29th, 2013, 01:42 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My gut feeling was that your development environment has an issue. And then I found this: http://stackoverflow.com/questions/1...rflowexception

The other issues about the view hierarchy probably has something to do with updating the UI on a non-UI thread. I don't remember the book code having this problem though.

NullPointerException probably isn't network related. I don't have the book in front of me, but I don't think the GForce meter example used a network connection. All I can tell you is there is an object on line 95 is null and it probably shouldn't be. Or it needs a null check.
Reply With Quote
  #10 (permalink)  
Old December 1st, 2013, 07:09 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by uler3161 View Post
My gut feeling was that your development environment has an issue. And then I found this: http://stackoverflow.com/questions/1...rflowexception
Ahh, thank you. This actually solved a lot of my issues and I have a working AVD without errors now, yeah! However, since I will be receiving my android device tomorrow (Moto G), which I hope I will be able to update to 4.4 eventually, developing for API19 would be nice...

Quote:
The other issues about the view hierarchy probably has something to do with updating the UI on a non-UI thread. I don't remember the book code having this problem though.

NullPointerException probably isn't network related. I don't have the book in front of me, but I don't think the GForce meter example used a network connection. All I can tell you is there is an object on line 95 is null and it probably shouldn't be. Or it needs a null check.
Hmm, most of the errors are gone now, but the NullPointerException remains:
Quote:
E/AndroidRuntime(1159): FATAL EXCEPTION: Thread-102
E/AndroidRuntime(1159): java.lang.NullPointerException
E/AndroidRuntime(1159): at com.paad.earthquake.EarthquakeListFragment.refresh Earthquakes(EarthquakeListFragment.java:95)
E/AndroidRuntime(1159): at com.paad.earthquake.EarthquakeListFragment.access$ 0(EarthquakeListFragment.java:55)
E/AndroidRuntime(1159): at com.paad.earthquake.EarthquakeListFragment$1.run(E arthquakeListFragment.java:47)
E/AndroidRuntime(1159): at java.lang.Thread.run(Thread.java:841)
By now I have, besides trying it on two different PC, even reinstalled Windows 7 on a fresh hard drive with only 32bit versions (I usually run Win7 x64 and thought maybe that could be a source for issues). Still the same thing (I experimented with all variations of API11 and API18 again).

I would be really interested if this actually works on somebody's AVD (and then, of course, how)!

Thank you again for your time!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Earthquake Chapter 6 newbie123 BOOK: Professional Android 4 Application Development 7 January 21st, 2013 07:09 AM
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 05:52 AM
Chapter 9 Earthquake 1 MellowFellow BOOK: Professional Android 2 Application Development 14 August 23rd, 2010 05:40 PM
Please help: Chapter 9 Earthquake 4 dahe BOOK: Professional Android 2 Application Development 0 July 21st, 2010 04:41 PM
Chap. 9 Earthquake app does not work. pgmr26 BOOK: Professional Android 2 Application Development 1 March 27th, 2010 09:14 AM



All times are GMT -4. The time now is 01:08 PM.


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