IllegalStateException - no references to my code in stacktrace - android

this stacktrace was submitted to my project issue tracker.
As you there is no references to my code, so does anybody know how to fix it?
I'm using support library v19.0.1 and I can provide more details about device/platform if need
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:486)
at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:179)
at android.support.v7.app.ActionBarActivity.onBackPressed(ActionBarActivity.java:250)
at android.app.Activity.onKeyUp(Activity.java:2099)
at android.view.KeyEvent.dispatch(KeyEvent.java:2575)
at android.app.Activity.dispatchKeyEvent(Activity.java:2329)
at android.support.v7.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchKeyEvent(ActionBarActivityDelegateICS.java:250)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3344)
at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3317)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2464)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

First change i made is
getSupportFragmentManager().beginTransaction()
.add(R.id.container,new CatListFragment(null)).commitAllowingStateLoss();
Second change is intercept onPause onStop and onResume for the activity, maintain a flag if application is in paused state(or any other way). Intention is not to call .commit() or .commitAllowingStateLoss() in paused state. Once app is resumed you can call the FragmentManager commit. Worked for me :)

Related

Can android sdk free your memory before you are done with it?

My app is getting crash reports on google play. I was told that android can release your memory on you, is this really true.
I'm getting a NullPointerException error on the following line
if (butSettings.Intersect(x, y))
I'm assuming butSettings is null.
I'm confuse because butsettings is set up on the onCreate. It's member functions are then called on the onUpdate which gets called every .1 of a second.
line
if (butSettings.Intersect(x, y))
is in my onTouch event. So I'm assuming butSettings member functions would have gotten called in the onDraw. So why is this truing into a null?? Could android being freeing it?
stack trace from google
java.lang.NullPointerException
at com.fairhvaenapps.toddpuzzlefree.cMainView.onTouchEvent(cMainView.java:267)
at android.view.View.dispatchTouchEvent(View.java:5588)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1684)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2060)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398)
at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2008)
at android.view.View.dispatchPointerEvent(View.java:5768)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2911)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2485)
at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:852)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2494)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Android can destroy your activity at any moment, that's why you have to properly do initialization in onCreate and properly dispose of things in onDestroy. However, you will never end up with a NullPointerException because of this; Android will not just simply remove a reference to an object because of this. The exception you're seeing is because of some bug in your code. It has nothing to do with memory.

Null pointer exception on doing webview.loadUrl()

I've been getting this error in my developer portal. I'm not sure why. Stack trace tracks back into some internal function call inside WebView object.
java.lang.NullPointerException
at android.webkit.WebView.loadUrlImpl(WebView.java:3008)
at android.webkit.WebView.loadUrlImpl(WebView.java:3047)
at android.webkit.WebView.loadUrl(WebView.java:3040)
at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175)
at com.myapp.android.PreviewActivity.access$14(PreviewActivity.java:174)
at com.myapp.android.PreviewActivity$ActionBarItemClickListener.onClick(PreviewActivity.java:901)
at android.view.View.performClick(View.java:3644)
at android.view.View$PerformClick.run(View.java:14313)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
In my code at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175), there is this line
webView.loadUrl("javascript:MyApp.onClick('" + action + "');");
I'm actually invoking a javascript call from my java code. Has anyone faced this issue before?
I found the answer myself. If webView.destroy() has already been called then calling webView.loadUrl() will cause this exception.
It seems that your webview is null. Did you call findView before?

getting stragne unexpected error sometime using ActionBarSherlock

I am using ActionBarShelock and some time get force close with this error cant find how to handle it .
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sps/com.sps.ui.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.app._ActionBarSherlockTrojanHorse.onCreatePanelMenu(_ActionBarSherlockTrojanHorse.java:52)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:556)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:60)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:154)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
at com.android.internal.policy.impl.PhoneWindow.restorePanelState(PhoneWindow.java:1677)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1627)
at android.app.Activity.onRestoreInstanceState(Activity.java:928)
at android.app.Activity.performRestoreInstanceState(Activity.java:900)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2037)
... 11 more
In the r7 support library, the version on which the current release (4.1.0) of ActionBarSherlock is based, the FragmentManager class checked if mActive != null before dispatching menu events to the fragments contained in the mAdded list. This code was copied into ActionBarSherlock since it uses its own MenuItem type and does its own dispatching.
In a subsequent release of the support library, it was found that this check was no longer representative of whether or not mAdded had been instantiated with a list or not. Commit 464b6f3c changed the conditional check to mAdded != null.
ActionBarSherlock has not had a release since this fix was made. However, it was updated on the dev branch in commit 69fe6fd to be included in the next release.

Why this code can not run on HTC but run on other android phones?

I mean I write this code :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
it is run on sony ,samsung... but it is error on htc phone(wildfire s).Why?
maybe this is reason?
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:381)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:226)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
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:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Seems like your activity is not alivevisible when you are setting this flag to its window.
Instead, i would suggest you to add the following attribute to any of your view.
android:keepScreenOn="true"
Another reason could be due to orientation change. If you are running an AsyncTask and meanwhile the orientation changes, it actually destroys the activity and recreates it. Now if AsyncTask completes its job, it would try to update the activity which is no longer available and gets crash.

NullPointerException encountered in findFragmentByTag - android v4 support package

I'm trying to add a couple of fragments to my activity. Both the fragments are added (when they're not added) and removed (when they're already added) in onTouchEvent(MotionEvent).
1) In portrait, I have touched the LCD a couple of times, so, the fragments are added and detached.
2) Orientation changed and when I touch the LCD again, I first do a findFragmentByTag(String), with the FragmentManager obtained using getSupportFragmentManager(), to check if the fragment is already added (before adding it). This is where I encounter a crash.
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.findFragmentByTag(FragmentManager.java:1211)
at com.samsung.sec.mtv.ui.common.MtvFragHandler.addFrag(MtvFragHandler.java:169)
at com.samsung.sec.mtv.ui.liveplayer.MtvUiLivePlayer.onTouchEvent(MtvUiLivePlayer.java:298)
at android.app.Activity.dispatchTouchEvent(Activity.java:2105)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1730)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2218)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1889)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
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:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)

Categories

Resources