I'm showing an interstitial at the end of a game level. When the user presses the Back button very quickly, a crash sometimes occurs:
java.lang.IllegalStateException
at android.media.MediaPlayer.getDuration(Native Method)
at com.google.android.gms.ads.internal.overlay.l.a(SourceFile:180)
at com.google.android.gms.ads.internal.overlay.n.run(SourceFile:204)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
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:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
I'm using the latest version of Google Play Services (v25). The code for showing Admob interstitial is already inside a try-catch block, but this doesn't help.
Is there a way to prevent that crash?
Are you sure your try catch block has caught IllegalStateException ?
try{
}catch(IllegalStateException e){
}
if not you must catch illegalStateException
There is no way to catch the exception.
It is thrown from the UI thread with none of your code in the stack.
It will undoubtedly be fixed by Admob in the near future.
Related
Following the suggestions provided in this question I modified my AdMob code to be compliant with the recommendations, that effectively worked reducing the number of exceptions that were appearing. However a new exception is rising.
The code is the following:
#Override
protected void onDestroy() {
if ( adView != null ) {
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnDestroy, destroying the Adview");
}
super.onDestroy();
}
The method adView.destroy() appears to work well as the LogCat message is published. Just after this message I am getting the following exception on WebView:
java.lang.NullPointerException
at android.webkit.WebViewClassic.loadDataWithBaseURL(WebViewClassic.java:2741)
at android.webkit.WebView.loadDataWithBaseURL(WebView.java:919)
at com.google.android.gms.ads.internal.request.n.run(SourceFile:206)
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: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)
Unfourtunately I am not able to find a way to reproduce the problem but is happening in production regularly. I have not been able to find any problem, has somebody any hint of what I can do?
One of Google Mobile Ads SDK Team said (March 14),
We looked into this issue when it was first reported, and a fix has been released within Google Play services. You should see fewer and fewer instances as your users' devices update to the new version.
Refer to https://groups.google.com/forum/#!topic/google-admob-ads-sdk/oYpQI_L14Tg
This occurs when the WebView is destroyed before loadDataWithBaseUrl is called( probably by other thread). In AdMob code, i saw that they handle this now as follows
public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
synchronized(this) {
if(!this.isDestroyed()) {
super.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
} else {
Log.d("The webview is destroyed. Ignoring action.");
}
}
}
So it should not occur now.
From the 25th of june two unrelated apps that are using ads started to have this NPE
java.lang.NullPointerException
at zo.a(SourceFile:172)
at aeh.a(SourceFile:120)
at afw.run(SourceFile:14)
at afy.run(SourceFile:30)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
I think this is related to google play services update. Is anyone able to help me out on this issue?
Just to confirmed that the issue is related to play service I have managed to get this from crashlytics from a thread called AdWorker:
thread
at java.lang.Object.wait(Object.java)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:973)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1282)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:207)
at zo.a(SourceFile:147)
at zo.a(SourceFile:170)
at aeh.a(SourceFile:120)
at afw.run(SourceFile:14)
at afy.run(SourceFile:30)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
it is not the right place... but there is no place at all where to report them
Number of exceptions it has double from 1 july, it is now almost 3 times what it was the 27th of june.
Issue on android google code project
The discussion is now in this thread on admob google Heading group
Last reply from google "We're aware of these crashes and are working on fixes. We hope to push out these fixes in the next week or two." (July 7th)
Found this solution by Mateusz Matela at https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8.
I have tried on a Motorola DEFY+ that crashed from this bug two out of three times. It seems to work even when the warnings assositated with this bug appears in the log. It even says "AdWorker thread thrown an exception". My ads even reappeard when continuing to use the app.
final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable ex) {
if (thread.getName().startsWith("AdWorker")) {
Log.w("ADMOB", "AdWorker thread thrown an exception.", ex);
} else if (defaultHandler != null) {
defaultHandler.uncaughtException(thread, ex);
} else {
throw new RuntimeException("No default uncaught exception handler.", ex);
}
}
});
Today, Google posts this : http://android-developers.blogspot.fr/2014/07/google-play-services-5.html
And now it works for me. Just try again to update the GooglePlayService in your mobile and update your ADT.
Edit :
Code to check GPS version :
// Check if GooglePlay Service is good;
resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getActivity());
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this.getActivity(), 1).show();
rootView = inflater.inflate(R.layout.fragment_googleplayerror, container, false);
return rootView;
} else {
Log.i(Tag, "This device is not supported.");
getActivity().finish();
}
}
I got exactly same errors on different android versions after updating admob to google play services.
I think it can't be solved on user side.
It is related to Play services update, see sample crash log below. Since it crashes onCreate it might be happening when user click on an advert or a specific type of advert
USER_COMMENT=
ANDROID_VERSION=4.1.2
APP_VERSION_NAME=8.9
BRAND=samsung
PHONE_MODEL=GT-I9100
CUSTOM_DATA=
STACK_TRACE=java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxx/com.google.android.gms.ads.AdActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at acm.a(SourceFile:215)
at acz.onTransact(SourceFile:58)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.internal.ck$a$a.onCreate(Unknown Source)
at com.google.android.gms.ads.AdActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
... 11 more
java.lang.NullPointerException
at acm.a(SourceFile:215)
at acz.onTransact(SourceFile:58)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.internal.ck$a$a.onCreate(Unknown Source)
at com.google.android.gms.ads.AdActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
I was seeing the exact same issue with one of my apps since Jun 25th as well. You are right this is a Google issue, I think I have managed to resolve it by updating my Android Support Library to version 20 (I was using android-support-v4.jar) and my Google Play Services to version 17.
I am not sure which of the two revisions resolved this but it's been 24 hours and the Crash reports have stopped.
EDIT:
Sorry this is still not resolved. But I got a response from the AdMod SDK team that they are looking into it. https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8
This is a partial solution and it seems (so far) to fix 100% the crashes: you should postpone the ad request a few milliseconds to avoid this crash!
Simplified example:
Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
super.handleMessage(msg);
}
};
if (handler != null) {
handler.sendEmptyMessageDelayed(0, 200);
}
I have discovered a workaround.
In my case, I was showing the ad from within a service running in a custom process. For example:
<service
android:name="com.example.MyService"
android:exported="false"
android:process=":svc"
/>
In my AndroidManifest.xml, I then set the same android:process attribute for the declared AdActivity, and the problem went away.
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:process=":svc"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
/>
In the case of my application, I don't particularly care which process the ad activity runs in, so this workaround is sufficient. Hopefully this will be of some use to others.
I have find temporary semi-solution. I use thiagolr advice above with delayed ad request:
Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
super.handleMessage(msg);
}
};
if (handler != null) {
handler.sendEmptyMessageDelayed(0, 200);
}
Also I removed onResume and onPause methods, so I don't know which solution helps me,
but beforee this workaround I had 100-130 java.lang.NullPointerException at zo.a(SourceFile:172) per day. After this workaround I had 6-10 NullPointerException per day. If you want you could try this solutions separately to define which of them helps.
My removed methods in activity:
// #Override
// public void onPause() {
// adView.pause();
// super.onPause();
// }
//
// #Override
// public void onResume() {
// super.onResume();
// adView.resume();
// }
According to: https://groups.google.com/forum/#!topic/google-admob-ads-sdk/DkjtCx_Zvn8
Some have had a success by adding android:theme="#android:style/Theme.Translucent" to activity android:name="com.google.android.gms.ads.AdActivity" in the manifest.
I'm rolling out a new version with that fix now. Will see in a couple of days if it helps.
Move to using other ad sdk. I tried most of the thing mentioned and error still remains.
And i personally hate applying such hacks in code. So decided to switch rather using google ad sdk with crashes and bugs.
I'm new to java/android and trying to help out with an open source project. I decided I could learn the most from trying to fix bugs and so I've been running Monkey on the app to start generating crash reports with bugsense (I don't have access to play.google crash reports). I consistently run into the crash below and since it doesn't identify where in the code the app is having problems, I'm not even sure what exactly the problem is. I'm not asking for a line by line fix (although it is open source) but some helpful hints would be much appreciated.
Complete Repo: https://github.com/rackspace/android-rackspacecloud
Stacktrace + source: http://pastebin.com/YkX7NvdD
Stacktrace:
// CRASH: com.rackspace.cloud.android (pid 3330)
// Short Msg: java.lang.NullPointerException
// Long Msg: java.lang.NullPointerException
// Build Label: google/takju/maguro:4.1.1/JRO03C/398337:user/release-keys
// Build Changelist: 398337
// Build Time: 1341437384000
// java.lang.NullPointerException
// at android.widget.Spinner$DialogPopup.dismiss(Spinner.java:828)
// at android.widget.Spinner$DialogPopup.onClick(Spinner.java:862)
// at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
// at android.widget.AdapterView.performItemClick(AdapterView.java:298)
// at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
// at android.widget.AbsListView.onKeyUp(AbsListView.java:2996)
// at android.widget.ListView.commonKey(ListView.java:2196)
// at android.widget.ListView.onKeyUp(ListView.java:2051)
// at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
// at android.view.View.dispatchKeyEvent(View.java:7086)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1354)
// at android.widget.ListView.dispatchKeyEvent(ListView.java:2026)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892)
// at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369)
// at android.app.Dialog.dispatchKeyEvent(Dialog.java:702)
// at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
// at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575)
// at android.view.ViewRootImpl.deliverKeyEvent(ViewRootImpl.java:3531)
// at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3113)
// at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
// at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
// at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
// at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
// at android.os.MessageQueue.nativePollOnce(Native Method)
// at android.os.MessageQueue.next(MessageQueue.java:125)
// at android.os.Looper.loop(Looper.java:124)
// 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)
//
** Monkey aborted due to error.
Events injected: 5252
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=23 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=47382ms (0ms mobile, 47382ms wifi, 0ms not connected)
** System appears to have crashed at event 5252 of 10000 using seed 0
According to the code I am seeing at GrepCode, we have this :
public void dismiss() {
mPopup.dismiss();
mPopup = null;
}
So your NPE is caused by mPopup which is private AlertDialog of DialogPopup (private class of Spinner), probably the dialog to show the options of the spinner when you click it. mPopup is only set to something different from null at DialogPopup.show(). That method is called at Spinner.performClick(),i.e., when the spinner is clicked.
But then this is the weird part. The stack trace seem to be when an item of the mPopup was clicked, because DialogPopup is set as its OnClickListener. So at that point mPopup should not be null. But when DialogPopup.dismiss() it is null.
What can explain that? Here's my hypothesis. Well, monkey usually is pretty fast. Faster than actual users. It might be able to click two items before the mPopup was really dismissed by the first DialogPopup.onClick(). So we have two calls to DialogPopup.dismiss(), with the second cauing the NPE.
So here are my conclusions:
Because we are dealing only with internal classes and your code is not responsible for triggering the code that crashed, this is very likely an Android platform bug.
To fix this you must be able to reproduce and debug in eclipse in order to fully understand what is happening . You will need to download the Android platform code inorder to be able to step into the spinner code. Alternatively you can put log on the Spinner code and build Jelly Beans and flash your phone ( or replace the framework.jar)
If my hypothesis is correct, then debugging with ecplise won't help. You will need the logs to debug the problem. But if my hypothesis is right, then we think we should not worry. Normal user will hardly be able to click so fast.
You could advice the Android guys to do a if-null check. But only after you found the real root cause. Otherwise , you will be maskig the problem
I have a serius problem with my notification.
Sometimes when my app post the same custom notification I get this error:
android.app.RemoteServiceException: Bad notification posted from package com.packagename: Couldn't expand RemoteViews for: ClassName(package=com.packagename id=0 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x22))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1093)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3906)
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:840)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
at dalvik.system.NativeStart.main(Native Method)
What I have to do?
The notification contains only LinearLayout, TextViews and ImageViews and it works perfect most of the time.
There is a way to surround this error with try/catch so in this way android not stop my app?
Many thanks...
1) http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/app/ActivityThread.java#ActivityThread
From here we can see that this error can arise only in the one case:
case SCHEDULE_CRASH:
throw new RemoteServiceException((String)msg.obj);
2)http://openstorage.gunadarma.ac.id/android/sdk/sdk_310712/sources/android-15/android/app/ApplicationThreadNative.java
case SCHEDULE_CRASH_TRANSACTION:
{
data.enforceInterface(IApplicationThread.descriptor);
String msg = data.readString();
scheduleCrash(msg);
return true;
}
So this error arises from the ApplicationThreadNative
You can try to track ahead and maybe you will find the cause of this error.
I don't really instantiate an AndroidHttpClient anywhere in my code, but I do start a recognizer intent, which yields this exception at some point when my application runs:
Leak found
java.lang.IllegalStateException: AndroidHttpClient created and never closed
at android.net.http.AndroidHttpClient.<init>(AndroidHttpClient.java:152)
at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:138)
at com.google.android.voicesearch.speechservice.SpeechServiceHttpClient.<init>(SpeechServiceHttpClient.java:59)
at com.google.android.voicesearch.speechservice.ServerConnectorImpl.<init>(ServerConnectorImpl.java:85)
at com.google.android.voicesearch.VoiceSearchContainerImpl.createRecognitionController(VoiceSearchContainerImpl.java:83)
at com.google.android.voicesearch.GoogleRecognitionService.onCreate(GoogleRecognitionService.java:65)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2066)
at android.app.ActivityThread.access$2500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
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:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Assuming the bug is not in Android's code but in mine, this leaked resource could have been created only in one of the following:
SpeechRecognizer.createSpeechRecognizer()
new RecognitionListener()
new Intent(SpeechRecognizer.RESULTS_RECOGNITION)
SpeechRecognizer.startListening(recognizerIntent)
But how do I know which one?
Assuming the bug is not in Android's code but in mine
The leak is in com.google.android.voicesearch, which is not your code.
If you can create a small sample project that demonstrates this leak, we can get an issue over to Google and hope that they will address it.
Why do you assume it's not in Android? SpeechRecognizer and RecognitionListener are in ASOP, so you can check (it's not there). Most probably SpeechServiceHttpClient uses an AndroidHttpClient internally. There is not much you can do but check you are calling all finalizer methods, if any (close(), shutdown(), etc), of the framework classes you are using.