Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: AFMA_getSdkConstants is not defined

Tags:

android

admob

I'm trying to add an AdMob ad to my android application but whenever I'm opening the activity that is supposed to display the ad I get this error:

I/Ads(11448): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"kw":[],"preqs":4,"session_id":"17111845472336325405","u_sd":2,"seq_num":"5","slotname":"MYUSERIDHERE","u_w":360,"msid":"com.lazyprogrammer.dartscore","adtest":"on","js":"afma-sdk-a-v6.0.1","mv":"8011019.com.android.vending","isu":"70069487A7A68D24BEF2581104A73318","cipa":0,"format":"360x50_mb","net":"wi","smart_h":"auto","app_name":"1.android.com.lazyprogrammer.dartscore","hl":"en","smart_w":"full","u_h":613,"carrier":"26203","ptime":225498,"u_audio":1});</script></head><body></body></html>
E/Ads(11448): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
E/Web Console(11448): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
I/Ads(11448): AdLoader timed out after 60000ms while getting the URL.
D/webviewglue(11448): nativeDestroy view: 0x2bc958
I/Ads(11448): onFailedToReceiveAd(A network error occurred.)
I/Ads(11448): AdLoader timed out after 60000ms while getting the URL.
D/webviewglue(11448): nativeDestroy view: 0x5a1850
I/Ads(11448): onFailedToReceiveAd(A network error occurred.)

I can't find anything on this problem on google or elsewhere and I don't think I'm doing anything wrong.

Just in case, here is my xml snippet that is supposed to show the ad:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    ...

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="MyIDhere"
        ads:loadAdOnCreate="true"
        ads:testDevices="70069487A7A68D24BEF2581104A73318" />

</RelativeLayout>

Of course I took out all the - I think - unnecessary code for this problem but if it's necessary to see it I'll post it here as well.

I also took out my AdMob UnitID, you probably figured that out but I'm writing this here so that missing UnitId won't be an answer.

My Manifest has the right permissions listed:
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET

and i also have the AdActivity added with the right configChanges

like image 209
dr3minem Avatar asked May 23 '12 09:05

dr3minem


People also ask

How do I fix uncaught ReferenceError is not defined?

The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.

Is not defined error?

If you are using jQuery, Angular JS, or plain old JavaScript and getting "Uncaught ReferenceError: $ is not defined" error which means $ is either a variable or a method that you are trying to use before declaring it using the var keyword.


2 Answers

I had this error too and solved by loading the ad in separate thread (in ICS you're not allowed to perform network operation in the main thread)

(new Thread() {
                public void run() {
                     Looper.prepare();
                    adView.loadAd(new AdRequest());
                }
            }).start();
like image 77
user1345108 Avatar answered Oct 20 '22 01:10

user1345108


It's a connection problem. I fixed it by uninstalling my ad blocker...

like image 21
Patches Avatar answered Oct 19 '22 23:10

Patches