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 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 Search this Thread Display Modes
  #1 (permalink)  
Old September 25th, 2012, 10:33 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Earthquake Chapter 6

Hi. I am having problem running earthquake example in Chapter 6 on the emulator. I got a blank screen with the title of the activity. Any suggestions?

Last edited by newbie123; September 25th, 2012 at 11:09 PM.. Reason: More description
Reply With Quote
  #2 (permalink)  
Old September 26th, 2012, 02:01 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem solved. Must have typed something wrong...
Reply With Quote
  #3 (permalink)  
Old September 30th, 2012, 05:40 PM
Authorized User
Points: 189, Level: 3
Points: 189, Level: 3 Points: 189, Level: 3 Points: 189, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by newbie123 View Post
Problem solved. Must have typed something wrong...
I'm curious what you mistyped. I can't even get the downloaded code to run...

I'm stumped at this point...
Reply With Quote
  #4 (permalink)  
Old November 17th, 2012, 03:02 PM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by xcopy View Post
I'm curious what you mistyped. I can't even get the downloaded code to run...

I'm stumped at this point...
When I got the code for Earthquake it didn't work either. When I selected an AVD with 4.0.3 It worked fine.

My code is still crashing, but at least I got the sample working. It is somewhat frustrating that code that worked in 4.0.3 needs so many changes to work on 4.1.2. So far I have enjoyed this book the most so far.

The line of code that is blowing up is:

Code:
int responseCode = httpConnection.getResponseCode();
The sample plows right through this and works fine.

I will note that the sample code has differences when it comes to threads.

Last edited by pdevhecht; November 17th, 2012 at 04:32 PM..
Reply With Quote
  #5 (permalink)  
Old December 17th, 2012, 04:24 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Talking

I just spent 3 hours getting this to work, and hopefully this summary of issues with the initial Chapter 6 Earthquake example will save others some time:

1. In your Earthquake.java file (or whatever you named your project -- the main class), make sure that you change "public class Earthquake extends Activity" to "public class Earthquake extends FragmentActivity". Also doesn't hurt to delete the menu stuff.

2. To make the project compatible back to API 8 (which you should do -- look at http://developer.android.com/about/d...rds/index.html), be sure to (1) import android.support.v4.app.FragmentActivity in Earthquake.java, (2) import android.support.v4.app.ListFragment (not android.app.ListFragment) in EarthquakeListFragment.java and (3) make sure that android-support-v4.jar is in your libs folder (if not, right click on the top project folder and select Android Tools --> Add Support Library).

3. The download code for EarthquakeListFragment.java is not correct -- if you follow the code in the book it should be correct. In particular (1) handling as a background thread refreshEarthquakes() (see item 10 in the book on page 209), (2) handling as a background thread addNewQuake(quake) (see item 8 in the book on page 208-209), (3) adding a Handler (see item 8 in the book on page 207), and (4) making instance "quake" final (see item 8 in the book on page 208).

Good luck!
Reply With Quote
The Following User Says Thank You to silver_man For This Useful Post:
pdevhecht (December 17th, 2012)
  #6 (permalink)  
Old December 17th, 2012, 10:11 AM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default I will look into the support libs

Thanks for your thoughtful response. I haven't been using the support libraries, but you make a point that it would then be compatible back to API 8. I'm not exactly sure why one wouldn't just use the support libs always, is there some kind of performance issue?

I'm now on Chapter 8, so I got it to work somehow!!!
Reply With Quote
  #7 (permalink)  
Old December 19th, 2012, 02:20 AM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Location: Nanjing
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok, congratulations !
Reply With Quote
  #8 (permalink)  
Old January 21st, 2013, 07:09 AM
Authorized User
Points: 89, Level: 1
Points: 89, Level: 1 Points: 89, Level: 1 Points: 89, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default Ch6 Earthquake

Quote:
Originally Posted by newbie123 View Post
Hi. I am having problem running earthquake example in Chapter 6 on the emulator. I got a blank screen with the title of the activity. Any suggestions?
I experienced the same.
Check in logcat if you got this exception :

"android.view.ViewRoot$CalledFromWrongThreadExcept 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 also the code in the book with the thread does not work!!

I tried to call aa.notifyDataSetChanged() in the main thread, and delete aa.notifyDataSetChanged() from earthquakeListfragment.java, and invoked it with a button for instance.
Pressing the button (but first wait some seconds cause the procedure refresh_Earthquake is time consuming!) it filled the list with the earthquake entries.
For instance in earthquake.java's onCreate handler, (and also an extra button ListButton in main.xml) :
Code:
        button = (Button)findViewById(R.id.ListButton);
        button.setOnClickListener(new View.OnClickListener() {
			
	        @Override
	        public void onClick(View v) {
		    FragmentManager fm = getFragmentManager();
		    EarthquakeListFragment earthquakeList = 
		          (EarthquakeListFragment)fm.findFragmentById(R.id.EarthquakeListFragment);
		    earthquakeList.aa.notifyDataSetChanged();
				
		}
	});
Good luck.

Last edited by Kees; January 22nd, 2013 at 04:50 PM..
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
Chapter 9 Earthquake 1 MellowFellow BOOK: Professional Android 2 Application Development 14 August 23rd, 2010 04:40 PM
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 6 Sample Earthquake 2 sunrain BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 2 January 31st, 2009 04:06 PM



All times are GMT -4. The time now is 09:24 PM.


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