p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 (http://p2p.wrox.com/forumdisplay.php?f=432)
-   -   Chapter 6 Sample Earthquake 2 (http://p2p.wrox.com/showthread.php?t=72497)

sunrain January 30th, 2009 06:09 PM

Chapter 6 Sample Earthquake 2
 
Hello,

I get the following error when I click on a specific earthquake from the list of quakes: "The application com.paad.earthquake (process com.paad.earthquake) has stopped unexpectedly. Please try again."

The Logs show the following:

Code:

01-30 17:01:02.452: WARN/WindowManager(52): Attempted to add window with non-application token WindowToken{4345d4f8 token=null}.  Aborting.
01-30 17:01:02.462: DEBUG/AndroidRuntime(204): Shutting down VM
01-30 17:01:02.462: WARN/dalvikvm(204): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
01-30 17:01:02.471: ERROR/AndroidRuntime(204): Uncaught handler: thread main exiting due to uncaught exception
01-30 17:01:02.502: ERROR/AndroidRuntime(204): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.view.ViewRoot.setView(ViewRoot.java:388)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:90)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.app.Dialog.show(Dialog.java:212)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.app.Activity.showDialog(Activity.java:2279)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at com.paad.earthquake.Earthquake$1.onItemClick(Earthquake.java:72)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.widget.AdapterView.performItemClick(AdapterView.java:283)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.widget.ListView.performItemClick(ListView.java:3049)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1415)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.os.Handler.handleCallback(Handler.java:542)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.os.Handler.dispatchMessage(Handler.java:86)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.os.Looper.loop(Looper.java:123)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at android.app.ActivityThread.main(ActivityThread.java:3742)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at java.lang.reflect.Method.invoke(Method.java:515)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
01-30 17:01:02.502: ERROR/AndroidRuntime(204):    at dalvik.system.NativeStart.main(Native Method)

I am using the latest version of the sample code. Any reasons why?

Thanks!

Reto January 31st, 2009 12:28 PM

Quote:

Originally Posted by sunrain (Post 233988)
I am using the latest version of the sample code. Any reasons why?

It looks like a got a bit carried away with a couple of find-replace searches right before I uploaded the sample code. What's happened is I've used getApplicationContext() when I should be passing in the Activity's context.

What you need to do is fix these two lines, replacing getApplicationContext() with this, as shown below:

Code:

LayoutInflater li = LayoutInflater.from(getApplicationContext());
View quakeDetailsView = li.inflate(R.layout.quake_details, null);
   
AlertDialog.Builder quakeDialog = new AlertDialog.Builder(getApplicationContext());

Becomes:
Code:

LayoutInflater li = LayoutInflater.from(this);
View quakeDetailsView = li.inflate(R.layout.quake_details, null);
   
AlertDialog.Builder quakeDialog = new AlertDialog.Builder(this);

Sorry about that, I've got a few updates to the sample code pending that should be available in the next few days.

sunrain January 31st, 2009 04:06 PM

Thanks, that did the trick!


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

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