0

I'm trying to get adwhirl native ads into my app. I've set it up correctly as far as i can tell, and i can see i'm receiving my housead through adwhirl. But it's not showing anywhere. the logcat tells me its rotating every 15 seconds as should. The only error message i see having anything to do with this is : Layout is null!.

so i'm calling ad's like this in my activity:

 LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
            if (layout == null) {
              Log.e("AdWhirl", "Layout is null!");
              return;
            }
            int width = 320;
            int height = 72;
            DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
            float density = displayMetrics.density;
            width = (int) (width * density);
            height = (int) (height * density);
            AdWhirlAdapter.setGoogleAdSenseAppName("appname");
            AdWhirlAdapter.setGoogleAdSenseCompanyName("companyname");
            AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
            AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.adwhirl_layout);
            adWhirlLayout.setAdWhirlInterface(this);
            AdWhirlLayout adWhirlLayout2 = new AdWhirlLayout(this,"mykey");
            adWhirlLayout2.setAdWhirlInterface(this);
            adWhirlLayout2.setMaxWidth(width);
            adWhirlLayout2.setMaxHeight(height);
            RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            adWhirlLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
            layout.setGravity(Gravity.CENTER_HORIZONTAL);
            layout.addView(adWhirlLayout2, adWhirlLayoutParams);
            AdWhirlTargeting.setTestMode(true);    
            TextView textView = new TextView(this);
            textView.setText("Below AdWhirlLayout from code");
            layout.addView(textView, adWhirlLayoutParams);
            layout.setGravity(Gravity.CENTER_HORIZONTAL);
            AdWhirlTargeting.setTestMode(true);
            adWhirlLayout.addView(adWhirlLayout);

And this is my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl" 
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:id="@+id/layout_main" > 
<com.adwhirl.AdWhirlLayout 
        android:id="@+id/adwhirl_layout" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
/> 
<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 
</LinearLayout>

Ive googled so much for this, and i'm coming up empty. Anyone have any pointers for me?

Havihavi
  • 652
  • 1
  • 9
  • 26

2 Answers2

0

Have you done setContentView(R.layout.main) so that it knows about your main.xml?

RajPara
  • 2,281
  • 1
  • 16
  • 9
  • Yeah, it's in onCreate. additionally, whenever i put the < webview tag above the < com.adwhirl tag in main.xml it will crash, so i'm thinking it's just my xml being badly written. would love a working example of a main.xml with webview and adwhirl! Thanks for replying :) – Havihavi Mar 19 '12 at 16:36
  • Does it work if you remove the tag from your xml temporarily? – RajPara Mar 19 '12 at 17:02
  • No, then the entire app crashes with fatal exception:main. but the app does launch in webview, so that makes sense. i tried stripping that away, but it just crashes. does it help you if i add the oncreate section to my question? – Havihavi Mar 19 '12 at 17:09
0

As we discussed here, the main reason this wasn't working was the application was trying to use PhoneGap, which isn't compatible with AdWhirl.

For any future Android AdWhirl Developers, note that if you have defined an AdWhirlLayout in your manifest:

<com.adwhirl.AdWhirlLayout 
    android:id="@+id/adwhirl_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/>

and you have the AdWhirl Key in your manifest:

<meta-data android:value="643eb700781e4f47b017ea27d1aba3be" android:name="ADWHIRL_KEY" />

then you don't need to write any additional code. The only things you may want to do are set how long the configuration is valid (this example sets it to 5 minutes) and request test ads during development:

AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setTestMode(true);
Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28