Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 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 Search this Thread Display Modes
  #11 (permalink)  
Old August 18th, 2010, 01:34 PM
Registered User
 
Join Date: Aug 2010
Posts: 13
Thanks: 1
Thanked 2 Times in 2 Posts
Default Changes to get Chapter 10 Earthquake 3 Working

Hi,
I started seeing the same exception, java.lang.ClassCastException: java.lang.String.

By creating a new project, mellowfellow, you cleared out the existing preferences data. The preference data is stored as strings, but if you look at the onStartCommand in EarthquakeService, it's attempting to read an int.

Run Reto's sample code, Chapter 10 Earthquake 3, and change the preferences using the preferences menu. Restart the app and you will see the ClassCastException again.

To fix the code replace this:
Code:
    int minMagIndex = prefs.getInt(Preferences.PREF_MIN_MAG, 0);
    if (minMagIndex < 0)
      minMagIndex = 0;

    int freqIndex = prefs.getInt(Preferences.PREF_UPDATE_FREQ, 0);
    if (freqIndex < 0)
      freqIndex = 0;

    boolean autoUpdate = 
      prefs.getBoolean(Preferences.PREF_AUTO_UPDATE, false);

    Resources r = getResources();
    int[] freqValues = r.getIntArray(R.array.update_freq_values);

    int updateFreq = freqValues[freqIndex];
with this:
Code:
    int updateFreq = Integer.parseInt(prefs.getString(Preferences.PREF_UPDATE_FREQ, "60"));

    boolean autoUpdate = 
      prefs.getBoolean(Preferences.PREF_AUTO_UPDATE, false);
Reply With Quote
  #12 (permalink)  
Old August 18th, 2010, 02:27 PM
Authorized User
 
Join Date: Jul 2010
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Default Error code

Yes I started getting that Exception again.

I tried the fix you gave, but now I'm getting a different error:

08-18 13:49:18.660: WARN/dalvikvm(714): Exception Ljava/lang/RuntimeException; thrown during Landroid/os/AsyncTask;.<clinit>
08-18 13:49:18.660: WARN/dalvikvm(714): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
08-18 13:49:18.710: ERROR/AndroidRuntime(714): FATAL EXCEPTION: earthquakeUpdates
08-18 13:49:18.710: ERROR/AndroidRuntime(714): java.lang.ExceptionInInitializerError
08-18 13:49:18.710: ERROR/AndroidRuntime(714): at com.paad.earthquake1.EarthquakeService.refreshEart hquakes(EarthquakeService.java:250)
08-18 13:49:18.710: ERROR/AndroidRuntime(714): at com.paad.earthquake1.EarthquakeService.access$0(Ea rthquakeService.java:247)
08-18 13:49:18.710: ERROR/AndroidRuntime(714): at com.paad.earthquake1.EarthquakeService$1.run(Earth quakeService.java:191)
08-18 13:49:18.710: ERROR/AndroidRuntime(714): at java.util.Timer$TimerImpl.run(Timer.java:289)
08-18 13:49:18.710: ERROR/AndroidRuntime(714): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-18 13:49:18.710: ERROR/AndroidRuntime(714): at android.os.Handler.<init>(Handler.java:121)
Reply With Quote
  #13 (permalink)  
Old August 18th, 2010, 07:53 PM
Registered User
 
Join Date: Aug 2010
Posts: 13
Thanks: 1
Thanked 2 Times in 2 Posts
Default Chapter 9 Earthquake 4

Hi MellowFellow,
I'd think you'd get better results running "Chapter 9 Earthquake 4" which uses an alarm instead of timer.

I had a lot of force closes while running Chapter 9 Earthquake 1-3. Reto mentions:

Quote:
At this stage the earthquake processing is done in a Service, but it’s still being executed on the main GUI
thread. Later in this chapter you’ll learn how to move time-consuming operations onto background
threads to improve performance and avoid ‘‘Force Close’’ messages.
Similarly, the Service is constantly running, taking up valuable resources. Later sections will explain
how to replace the Timer with Alarms.
Reply With Quote
  #14 (permalink)  
Old August 19th, 2010, 05:18 PM
Authorized User
 
Join Date: Jul 2010
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Default Earthquake 4

I got Earthquake 4 running now after including the last fix you gave me, thanks. But I'm still seeing a non-fatal cursor error popping up whenever a new earthquake is detected (the same cursor not closed error we had before). The preferences screens also do not work anymore, they cause a force closure when selected.
Reply With Quote
  #15 (permalink)  
Old August 23rd, 2010, 04:40 PM
Registered User
 
Join Date: Aug 2010
Posts: 13
Thanks: 1
Thanked 2 Times in 2 Posts
Default Cursor fixes

Hi MellowFellow,
You have to apply the same two fixes from Chapter 7 (addNewQuake and loadQuakesFromProvider) described here:
Fix: Chapter 7 - Earthquake IllegalStateException Finalizing cursor

addNewQuake is now in EarthquakeService.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 05:52 AM
Please help: Chapter 9 Earthquake 4 dahe BOOK: Professional Android 2 Application Development 0 July 21st, 2010 03:41 PM
chapter 5 Earthquake EricTapia BOOK: Professional Android 2 Application Development 2 April 14th, 2010 12:47 AM
Chapter 8 Earthquake Notification woods620 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 December 23rd, 2009 09:57 AM
Chapter 6 Earthquake using Provider abowman BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 0 March 9th, 2009 05:19 PM



All times are GMT -4. The time now is 07:22 PM.


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