I tried to search for this problem but this error doesn't look to be the same as this error (my google play version is newer and notice that the error is at a different line of WebViewClassic, so might be different error or the same in a newer version) but I have received the exactly same error exception from webview
java.lang.NullPointerException
at android.webkit.WebViewClassic$WebViewInputConnection.setNewText(WebViewClassic.java:583)
at android.webkit.WebViewClassic$WebViewInputConnection.setComposingText(WebViewClassic.java:323)
at android.webkit.WebViewClassic$WebViewInputConnection.commitText(WebViewClassic.java:339)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:279)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
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:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
However I am not using any webview class directly. However, this problem might be related to AdView, but I don't understand how. My code is the following:
#Override
public void onPause() {
//TODO: these lines are created because onPuase of Adview doesn't work
if ( adView != null ) {
adView.pause();
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnPause, pausing the Adview");
}
super.onPause();
}
The error appears after the Log.i line, I would have expected this error to appear when AdView was called but not after. Is possible that this error is coming from a threaded action? Any idea how to avoid the problem?
As the example in https://developer.android.com/reference/com/google/android/gms/ads/AdView.html and the document for AdView.destroy(), you should only call adView.pause() in onPause(), and call adView.destroy() later in onDestroy().
The stack dump looks like another thread is accessing the destroyed AdView instance.
Related
I have a fragment containing VideoView and few other views.
public class PlayerPane extends Fragment {
... // static variables
private ImageView imageView;
private ImageView gifView;
private VideoView videoView;
private WebView webView;
private PDFView pdfView;
private MyScrollTextView scrollTextView;
private MediaPlayer audioPlayer;
...
#Override
public void onDestroyView() {
if (videoView != null && videoView.isPlaying()) {
LOGGER.info("Stopping videoView");
videoView.stopPlayback();
videoView.suspend();
videoView = null;
}
super.onDestroyView();
}
Whenever I remove this fragment while the video is being played, IllegalStateException is being thrown only in Android 4.0.4 (No issue with versions above 4.0.4).
Following is the exception:
java.lang.IllegalStateException
at android.media.MediaPlayer._reset(Native Method)
at android.media.MediaPlayer.reset(MediaPlayer.java:1236)
at android.widget.VideoView.release(VideoView.java:549)
at android.widget.VideoView.access$2300(VideoView.java:49)
at android.widget.VideoView$6.surfaceDestroyed(VideoView.java:537)
at android.view.SurfaceView.updateWindow(SurfaceView.java:581)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:290)
at android.view.View.dispatchDetachedFromWindow(View.java:9823)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3588)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3568)
at android.view.ViewGroup.removeView(ViewGroup.java:3516)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:951)
at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1123)
at android.app.BackStackRecord.run(BackStackRecord.java:592)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
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: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)
This is how I remove the fragment:
getFragmentManager.beginTransaction().remove(fragmentToBeRemoved).commit();
What is causing this IllegalStateException and how do I resolve this?
Anything pointing towards the solution would be of great help.
I suggest you take a different approach. Before you remove the fragment. Call this code before you attempt to remove the fragment.
videoView.stopPlayback();
videoView.suspend();
As is evident from the stack trace, when you remove the fragment, What Android does is to remove the VideoView (it's a view after all) which results in Videoview Attempting to release the underlying Mediaplayer. But the Mediaplayer itself might not be a state to be released which is causing this issue. Ideally this well might have been handled within VideocView, but looks like no
I think you call reset() after release() and this throw illegalstateexception.
See the code given on this URL. This is from the actual android github repo.
https://github.com/android/platform_frameworks_base/blob/866658261f4613e17ed6f39a74975ad0c9f40767/media/jni/android_media_MediaPlayer.cpp
the reset function from java calls the native _reset function which is given in the CPP file in this URL this is very hard to debug as it is a JNI calls which can not be debugged. So In my opinion it is very hard to know what is going wrong unless we really know what exactly you are doing
I have a DialogFragment which I am showing when a button is clicked. I have the following code in the onClick method of the button:
InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]);
infoDialog.show(getFragmentManager(), null);
However, I sometime get the following exception:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
This does not occur all the time, but it happens quite frequently. Can someone please explain to me what is causing this exception to be thrown, and how to solve this issue.
EDIT 1: Here is the stack trace:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1318)
at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1329)
at android.app.BackStackRecord.commitInternal(BackStackRecord.java:607)
at android.app.BackStackRecord.commit(BackStackRecord.java:586)
at android.app.DialogFragment.show(DialogFragment.java:230)
at <...>.MyActivity$1.onClick(MyActivity.java:73)
at android.view.View.performClick(View.java:4235)
at android.view.View$PerformClick.run(View.java:17484)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
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:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
hard to say without knowing more about your app - but this should help:
if (!getActivity().isFinishing()) {
InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]);
infoDialog.show(getFragmentManager(), null);
}
I just released an alarm app and it's been hell. It's breaking on certain devices when they try to open up the alarm list screen. I have no idea why it's breaking on some devices and not others. Every phone I've seen it tried on it works perfectly, but opening up the alarm list on some other devices blows it up. I'm really out of my depth for this kind of specific device compatibility issue.
The code at AlarmClock line 227 is this:
View changeSettings = findViewById(R.id.alarm_settings);
changeSettings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
}
});
And it references this line of xml:
<Button
android:id="#+id/alarm_settings"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0.0dip" android:layout_height="fill_parent"
android:text="#string/menu_settings"
android:layout_weight="1.0" />
This links to a settings activity I borrowed the source of from an adapted version of the android stock alarm, but it uses addPreferencesFromResource which is allegedly deprecated. Is that what's causing this problem?
This is the stack trace from the user's device:
Nexus 7
Touched setup alarm button and then it crashed
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nathantempelman.GoodMorningAlarmFree/com.nathantempelman.alarmclockfree.AlarmClock}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
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:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
... 11 more
Any help would be splendiferous. I know that it's happened on someone else's tablet as well, not sure if it's a tablet issue.
The app is here if anyone wants to give it a test: https://play.google.com/store/apps/details?id=com.nathantempelman.GoodMorningAlarmFree
you have a NullPointerException in your AlarmClock class in updateLayout method in line 227 :)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
i would check that code first.
as you didn't post any code, i cant help more at the moment :)
Just in case someone else stumbles across this, the problem in the end was that there was a separate layout file for tablets which I hadn't seen in the source codebase I borrowed for a part of my application. I had obviously added a bunch of functionality, but hadn't updated the tablet layout. The buttons to access the things I had added weren't in the tablet layout file. Ergo, null pointer exception only when a tablet device loaded the tablet layout file and searched for non existent objects in the display. When I deleted that file, everything worked perfectly.
I know, hurp and or durp. But maybe someone has the same problem and might want to check for this.
The main Activity in my Android app has a Gallery widget that loads XML layouts (containing TextViews and Images) through an efficient ImageAdapter. For the most part this works fine and I haven't had any problems on any of my devices or the emulator, but I have seen the following error in my logs. It looks like this is affecting less than 1% of users, but I'd like to know what's causing it, how to resolve it, or at least "catch" it and resolve gracefully. Any ideas?
java.lang.NullPointerException at
android.widget.Gallery.setUpChild(Gallery.java:772) at android.widget.Gallery.makeAndAddView(Gallery.java:751) at android.widget.Gallery.fillToGalleryLeft(Gallery.java:667) at android.widget.Gallery.trackMotionScroll(Gallery.java:378) at android.widget.Gallery$FlingRunnable.run(Gallery.java:1369) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3695) 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:842) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method)
I get this problem several days ago, please check your own gallery's adpater check its getView() methods,see if you return null in some if-cases,just replace return null with new View(context) (or other view but null) will simply solve this problem.Good luck
I'm getting the following exception with my app. I believe this happens when the user leaves the app for a long time then returns to it. I am unable to replicate it however it is showing up in my crash logs a lot. I have no idea why this is happening so any suggestions are greatly appreciated.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MyActivity}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4974)
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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
at java.util.ArrayList.get(ArrayList.java:306)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1764)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:198)
at com.myapp.MyActivity.onCreate(MyActivity.java:235)
at android.app.Activity.performCreate(Activity.java:4538)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
... 11 more
Line 235 is the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // line 235
My onSaveInstanceState() is pretty simple:
#Override
public void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putInt("id1", id1);
state.putInt("id2", id2);
state.putInt("id3", id3);
state.putInt("id4", id4);
}
I ran into this same problem, I believe it a bug with android. Take a look at this thread for a possible solution http://code.google.com/p/android/issues/detail?id=22404
I got the exact same problem, I followed the advice given in Kenny's link:
I used the following:
FragmentManager.enableDebugLogging(true);
This will display in the logs all the calls on the FragmentManager (fragments added, deleted, hidden etc.).
It allowed me to see what was wrong in my case, one of the fragments in my app was sometimes not saved properly in the instance and its content was null.
Then the crash happened with the same error log when the app tried to restore this null fragment from the instance.
In my case this fragment was a little special and created automatically. To be sure not to get the error again, I removed the fragment from the FragmentManager before exiting the Activity.
I had the same problem, occurring with orientation changes, but it only happened with older Android versions (4.0.4), newer versions like 4.4.2 were fine. I want to share with you how I fixed it.
As Kenny and Yoann suggested, I used
FragmentManager.enableDebugLogging(true);
and found out that too much removing has been done. I had to remove ft.remove(df) from my code and now it's fine with both versions mentioned above. This is my code:
if (savedInstanceState != null) {
final FragmentTransaction ft = getFragmentManager().beginTransaction();
final DialogFragment df = (DialogFragment) getFragmentManager().findFragmentByTag("tag");
if (df != null) {
df.dismiss();
// ft.remove(df);
frag = new MyDialogFragment();
frag.show(getFragmentManager(), "tag");
}
ft.addToBackStack(null);
ft.commit();
}
For the sake of completeness, this is what I have done in onSaveInstanceState(final Bundle outstate):
if (frag != null) {
getFragmentManager().putFragment(outState, "tag", frag);
}