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 App Example (http://p2p.wrox.com/showthread.php?t=89953)

ChristopherReichel April 28th, 2013 12:14 PM

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.

lanny November 26th, 2013 01:04 PM

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

uler3161 November 26th, 2013 01:50 PM

Different problem. Try running the network code on a separate thread.

lanny November 26th, 2013 08:38 PM

Just got the book. Thought it should be up to date. Wondering if any of the book editor cares about it.

uler3161 November 26th, 2013 08:57 PM

Quote:

Originally Posted by lanny (Post 294812)
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.

lanny November 26th, 2013 09:49 PM

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.

uler3161 November 26th, 2013 10:09 PM

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.

Markstar November 29th, 2013 07:28 AM

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

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.
[:o]

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). [:I]

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... [:confused:]:
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.

uler3161 November 29th, 2013 01:42 PM

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.

Markstar December 1st, 2013 07:09 PM

Quote:

Originally Posted by uler3161 (Post 294886)
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!


All times are GMT -4. The time now is 05:37 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.