Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 543

immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
08/13/16 03:35 PM (7 years ago)

Please help! Stuck Integrating Admob to BT_screen_map in android app

been trying for days now can't get ads working on BT_screen_map plugin. Looked through multiple posts on google but can't figure it out. I am trying the following code in BT_screen_map.java MobileAds.initialize(getActivity().getApplicationContext(), "ca-app-pub-*********************"); AdView adView = (AdView) getActivity().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators .addTestDevice("22F63C146F4BF48FB23F7549FCF36A0D") // An example device ID .build(); adView.loadAd(adRequest); and added the following to BT_screen_map.xml <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" /> Error i receive for this is java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference if i add getActivity().setContentView(R.layout.bt_screen_map); to java file i then get a heaps of fragment errors java.lang.IllegalArgumentException: No view found for id 0x7f0a0011 (com.*********:id/fragmentBox) for fragment BT_screen_map{3b62900 #1 id=0x7f0a0011 currentFragment} pleeeeeease help me ..... pulling my hair out
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/13/16 04:12 PM (7 years ago)
I can't say this is 'exact'. What I did was create a new plugin 'based' on the BT_screen_map, but it's not 'exactly the same. However, it should be really really close, if it's not the same. Give it a shot, and be willing to massage a few things if needed. In my layout (xml) file, it sort of looks like this: +++++++++++++++++++++++++++++++++++++++++ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/containerView" android:background="@android:color/transparent" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" > <fragment android:id="@+id/mapView" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/adView" android:layout_weight="1" tools:layout="@layout/bt_screen_map"/> <com.google.android.gms.ads.AdView android:id="@+id/sa_adView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adSize="SMART_BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> </LinearLayout> +++++++++++++++++++++++++++++++++++++++++ Then in my java class file, I added the Google Code almost where you did: +++++++++++++++++++++++++++++++++++++++++ View thisScreensView = inflater.inflate(R.layout.sw_smugaware, container, false); AdView adView = (AdView) thisScreensView.findViewById(R.id.sa_adView); BT_debugger.showIt("Declared AdView"); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("XXXXXXXXXXXXXXXXX") .build(); BT_debugger.showIt("Setup Ad Request"); adView.loadAd(adRequest); BT_debugger.showIt("Ad Request Complete"); +++++++++++++++++++++++++++++++++++++++++ I added this line in my 'strings.xml' file: +++++++++++++++++++++++++++++++++++++++++ <string name="banner_ad_unit_id">ca-app-pub-XXXXXXXXXXXXXXXXXXXXX</string> +++++++++++++++++++++++++++++++++++++++++ And I *think* that was it, but I forget things from day to day, so if it doesn't work, come on back and detail what the error log says, and we'll figure it all out together. Hopefully your results will be similar to this: https://dl.dropboxusercontent.com/u/115208762/Screenshot_guamflightsScreen4.png Hope this helps! Cheers! -- Smug
 
immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
like
08/13/16 04:39 PM (7 years ago)
*High Fives Smug* Thank you so much fixed my problem instantly. I had tried adding thisScreensView = inflater.inflate(R.layout.bt_screen_map, container, false); and other variations above my previous code but then id face other errors. instead i moved the java code to below thisScreensView = inflater.inflate(R.layout.bt_screen_map, container, false); and that fixed it. *happy dance*
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/13/16 07:36 PM (7 years ago)
In programming and in Real Estate: "Location, Location, Location". :) Glad you're up and running. Cheers! -- Smug
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.