Getting an error at Dialog.show - android

I am running 4 background tasks in a activity. But I was getting an error in one activity at
pDialog.show(). I am unable understand the. For some activities I got the same problem but I removed the progress dialog because those are medium priority but this one I need High priority. Here is my error. Can any tell me how to solve this error.
09-28 19:44:53.575: I/Choreographer(1120): Skipped 86 frames! The application may be doing too much work on its main thread.
09-28 19:44:54.374: E/WindowManager(1120): Activity com.example.newairways.Gscan has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d40860 V.E..... R.....ID 0,0-684,192} that was originally added here
09-28 19:44:54.374: E/WindowManager(1120): android.view.WindowLeaked: Activity com.example.newairways.Gscan has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d40860 V.E..... R.....ID 0,0-684,192} that was originally added here
09-28 19:44:54.374: E/WindowManager(1120): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
09-28 19:44:54.374: E/WindowManager(1120): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
09-28 19:44:54.374: E/WindowManager(1120): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
09-28 19:44:54.374: E/WindowManager(1120): at android.app.Dialog.show(Dialog.java:281)
09-28 19:44:54.374: E/WindowManager(1120): at com.example.newairways.Gscan$insert.onPreExecute(Gscan.java:304)
09-28 19:44:54.374: E/WindowManager(1120): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
09-28 19:44:54.374: E/WindowManager(1120): at android.os.AsyncTask.execute(AsyncTask.java:534)
09-28 19:44:54.374: E/WindowManager(1120): at com.example.newairways.Gscan$1.onClick(Gscan.java:201)
09-28 19:44:54.374: E/WindowManager(1120): at android.view.View.performClick(View.java:4204)
09-28 19:44:54.374: E/WindowManager(1120): at android.view.View$PerformClick.run(View.java:17355)
09-28 19:44:54.374: E/WindowManager(1120): at android.os.Handler.handleCallback(Handler.java:725)
09-28 19:44:54.374: E/WindowManager(1120): at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 19:44:54.374: E/WindowManager(1120): at android.os.Looper.loop(Looper.java:137)
09-28 19:44:54.374: E/WindowManager(1120): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-28 19:44:54.374: E/WindowManager(1120): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 19:44:54.374: E/WindowManager(1120): at java.lang.reflect.Method.invoke(Method.java:511)
09-28 19:44:54.374: E/WindowManager(1120): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-28 19:44:54.374: E/WindowManager(1120): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-28 19:44:54.374: E/WindowManager(1120): at dalvik.system.NativeStart.main(Native Method)
09-28 19:44:57.234: E/Trace(1146): error opening trace file: No such file or directory (2)

Use a Handler to show dialog if you are using AsyncTask or Thread in your program. And if the problem still exists, please try posting your code for further help :)

All progress dialogs should be closed before exiting an activity.
You have probably forgotten to close your progressDialog.
Close it in your onPostExecute() method
pDialog.dismiss();
Check out this SO link for more clarifation on windowleaked error.

Related

leaked window in facebook activity

when i am using facebook login button in my activity, logcat shows up this. I don't get it why this showing up I checked entire class never found a reference.
06-27 14:17:45.819 12019-12019/com.ets.medecord E/WindowManager﹕ Activity com.facebook.FacebookActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#4054a518 that was originally added here
android.view.WindowLeaked: Activity com.facebook.FacebookActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#4054a518 that was originally added here
at android.view.ViewRoot.<init>(ViewRoot.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:465)
at android.app.Dialog.show(Dialog.java:241)
at com.facebook.internal.WebDialog$DialogWebViewClient.onPageStarted(WebDialog.java:500)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:264)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
to check out activity code http://pastebin.com/qQqbvX6g
Window leak exception often occurs if Dialog not used properly(such as not finished before jumping to another activity). And Google has reminded developers that DialogFragment is a better choice than Dialog.

android leaked window force close

I have integrated zxing barcode scanner in my app. When the scanner gets a scan it takes the result and searches an external online database via a async task then opens a new activity based on the results. I am getting a force close that is not consistent, it does not happen every scan, only sometimes so I am having trouble figuring out why I am getting a leaked window error, and only sometimes:
09-25 21:02:48.105 24371-24371/com.beerportfolio.beerportfoliopro E/WindowManager﹕ Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
android.view.WindowLeaked: Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
at android.view.Window$LocalWindowManager.addView(Window.java:558)
at android.app.Dialog.show(Dialog.java:282)
at com.example.beerportfoliopro.GetBeerRateJSON.onPreExecute(GetBeerRateJSON.java:52)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:111)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:34)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
09-25 21:02:48.265 24371-24371/com.beerportfolio.beerportfoliopro E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:784)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:476)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:182)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog.dismiss(Dialog.java:311)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:74)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:27)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
From the stack trace, it looks like your Dialog isn't visible when the AsyncTask finishes its work. In that case, the call to dismiss() will crash the app.
You might try using Dialog.isShowing() to avoid the crash:
protected void onPostExecute(...) {
...
if (dialog.isShowing()) {
dialog.dismiss(); // or .cancel()
}
...
}

Android SQLite error with logcat

I'm having this error with my sqlite code but I don't know what to make of it because I am a beginner. Here is my logcat, any help would be appreciated. I can paste more code if you want.
My application just adds a contact to a database.
09-28 06:21:51.772: E/SQLiteLog(1564): (1) near "number": syntax error
09-28 06:21:51.803: E/SQLiteDatabase(1564): Error inserting mobile number=1233456 work address= home number=7658678 home address=123 Fake Street first name=John email address=jsmith#gmail.com last name=Smith work number=54372 notes=
09-28 06:21:51.803: E/SQLiteDatabase(1564): android.database.sqlite.SQLiteException: near "number": syntax error (code 1): , while compiling: INSERT INTO contacts(mobile number,work address,home number,home address,first name,email address,last name,work number,notes) VALUES (?,?,?,?,?,?,?,?,?)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at com.example.contactmanager.DatabaseHandler.addContact(DatabaseHandler.java:80)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at com.example.contactmanager.NewContactActivity$1.onClick(NewContactActivity.java:63)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.view.View.performClick(View.java:4240)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.view.View$PerformClick.run(View.java:17721)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.os.Handler.handleCallback(Handler.java:730)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.os.Looper.loop(Looper.java:137)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at java.lang.reflect.Method.invoke(Method.java:525)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-28 06:21:51.803: E/SQLiteDatabase(1564): at dalvik.system.NativeStart.main(Native Method)
I'm not looking for a very specific answer I just want to know where I should be looking to fix this problem. Thanks
EDIT: I put the underscores but now the error is saying there is no home address column in table contacts.
instead of mobile number its better if you give your field name as mobile_number (don't give the space). There might be possibilities where mobile and number can be considered as two separate fields.

Android Audio Service has leaked Service Connection

I am developing application on music player .
I am facing error like.
'*.MusicPlayerTabWidget has leaked ServiceConnection *
Please gave you comments regarding this.
I share my Logcat for this also.
05-01 10:38:03.226: W/KeyCharacterMap(4225): Using default keymap
05-01 10:38:03.429: E/ActivityThread(4225): Activity com.pvMusic.pvm.MusicPlayerTabWidget has leaked ServiceConnection com.pvMusic.pvm.MusicPlayerTabWidget$1#4051c6f0 that was originally bound here
05-01 10:38:03.429: E/ActivityThread(4225): android.app.ServiceConnectionLeaked: Activity com.pvMusic.pvm.MusicPlayerTabWidget has leaked ServiceConnection com.pvMusic.pvm.MusicPlayerTabWidget$1#4051c6f0 that was originally bound here
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:938)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:833)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ContextImpl.bindService(ContextImpl.java:879)
05-01 10:38:03.429: E/ActivityThread(4225): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
05-01 10:38:03.429: E/ActivityThread(4225): at com.pvMusic.pvm.MusicPlayerTabWidget.onStart(MusicPlayerTabWidget.java:175)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.Activity.performStart(Activity.java:3791)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-01 10:38:03.429: E/ActivityThread(4225): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 10:38:03.429: E/ActivityThread(4225): at android.os.Looper.loop(Looper.java:130)
05-01 10:38:03.429: E/ActivityThread(4225): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-01 10:38:03.429: E/ActivityThread(4225): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 10:38:03.429: E/ActivityThread(4225): at java.lang.reflect.Method.invoke(Method.java:507)
05-01 10:38:03.429: E/ActivityThread(4225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-01 10:38:03.429: E/ActivityThread(4225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-01 10:38:03.429: E/ActivityThread(4225): at dalvik.system.NativeStart.main(Native Method)
05-01 10:39:31.859: D/dalvikvm(4225): GC_EXPLICIT freed 166K, 46% free 3022K/5575K, external 557K/1031K, paused 52ms
05-01 10:39:31.906: D/dalvikvm(4225): GC_CONCURRENT freed 0K, 46% free 3022K/5575K, external 557K/1031K, paused 4ms+3ms
More over that if you have any reference tutorials for the music player please share with me..
Add unbindService(mConnection); in your onstop() method. The code will start working properly.
If you are doing a local binding to the service inside you activity , you need to make sure that you are disconnecting from the service whenever your activity is getting closed. Otherwise the app will start leaking the connection as in your error.
You're trying to show something after you're exit activity ( your thread came back ).
as shown here, you should override the onDestroy and dismiss the dialog that is running after the activity closes.
This can also happen when your Service has registered a BroadcastReceiver and didn't unregister.
So please unregister it in onDestroy
unregisterReceiver(mReceiver);
If you bind to getApplicationContext() instead, the binding will run as long as your app is running. If you bind to getContext(), and the Activity's context is destroyed, android notices that you didn't close the connection related to that context.

Unable to resolve ANR in android

Wen i install my apk file on android device and after installation wen i hit the open button my application does not start and shows force close.
The logcat output of my application is shown below :
09-28 12:14:57.651: INFO/ActivityManager(124): Starting activity: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.biz.mlm/.SplashScreen }
09-28 12:14:57.660: WARN/ActivityManager(124): Permission Denial: starting Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.biz.mlm/.SplashScreen } from ProcessRecord{44ffa660 1130:com.android.packageinstaller/10026} (pid=1130, uid=10026) requires android.permission.WRITE_CONTACTS
09-28 12:14:57.672: DEBUG/AndroidRuntime(1130): Shutting down VM
09-28 12:14:57.672: WARN/dalvikvm(1130): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): FATAL EXCEPTION: main
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.biz.mlm/.SplashScreen } from ProcessRecord{44ffa660 1130:com.android.packageinstaller/10026} (pid=1130, uid=10026) requires android.permission.WRITE_CONTACTS
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.os.Parcel.readException(Parcel.java:1247)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.os.Parcel.readException(Parcel.java:1235)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.app.Activity.startActivityForResult(Activity.java:2817)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.app.Activity.startActivity(Activity.java:2923)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at com.android.packageinstaller.InstallAppProgress.onClick(InstallAppProgress.java:224)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.view.View.performClick(View.java:2408)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.view.View$PerformClick.run(View.java:8816)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.os.Handler.handleCallback(Handler.java:587)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.os.Looper.loop(Looper.java:123)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at java.lang.reflect.Method.invoke(Method.java:521)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-28 12:14:57.700: ERROR/AndroidRuntime(1130): at dalvik.system.NativeStart.main(Native Method)
09-28 12:14:57.740: WARN/ActivityManager(124): Force finishing activity com.android.packageinstaller/.InstallAppProgress
Please help me by guiding me about what I have done wrong
EDIT :
The permissions in my manifest are :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<!-- <uses-permission android:name="android.permission.INSTALL_PACKAGES"/> -->
<application android:icon="#drawable/biz_logo"
android:permission="android.permission.WRITE_CONTACTS">
After this also it is behaving same
Looks like you need to add the permission
android.permission.WRITE_CONTACTS
to your manifest file.
Barry
The logcat output has everything you need to know :-)
Your app basically is writing contacts but it does not have permissions to do so (in Android, applications need to be given permissions explicitly for various operations).
Edit the file AndroidManifest.xml to include the following line/XML element:
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
within the
<manifest>
XML element, and then rebuild, reinstall and rerun.
For more information, take a look here: http://developer.android.com/guide/topics/manifest/uses-permission-element.html
yes i rebuilt it.my mistake was i have written in manifest <uses-permission android:name="android.permission.WRITE_CONTACTS" /> and also inside the application tag like this
<application android:icon="#drawable/logo"
android:permission="android.permission.WRITE_CONTACTS">
so i was getting force close.
This permission should be written only once in the manifest file

Categories

Resources