0

I am using Adwhirl first time in our apps but no joy.. Adwhirl supplied this demo code but it prompt an error "java.lang.ClassCastException: android.widget.LinearLayout" on selected line below please

    AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

        AdWhirlTargeting.setAge(23);
        AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);
        AdWhirlTargeting.setKeywords("online games gaming");
        AdWhirlTargeting.setPostalCode("94123");
        AdWhirlTargeting.setTestMode(false);

        ***AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layout_ad);***

        TextView textView = new TextView(this);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        int diWidth = 320;
        int diHeight = 52;
        int density = (int) getResources().getDisplayMetrics().density;

        adWhirlLayout.setAdWhirlInterface(this);
        adWhirlLayout.setMaxWidth((int) (diWidth * density));
        adWhirlLayout.setMaxHeight((int) (diHeight * density));

        layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        textView.setText("Below AdWhirlLayout");

        LinearLayout layout = (LinearLayout) findViewById(R.id.test_layout);

        layout.setGravity(Gravity.CENTER_HORIZONTAL);
        layout.addView(adWhirlLayout, layoutParams);
        layout.addView(textView, layoutParams);
        layout.invalidate();

XML here

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:gravity="bottom" android:id="@+id/layout_ad" />

Thanks

Yousuf Qureshi
  • 498
  • 2
  • 7
  • 21

2 Answers2

0

change this line to

AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layout_ad);// change this

to

LinearLayout adWhirlLayout = (LinearLayout ) findViewById(R.id.layout_ad);
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • I dont know what is AdWhilrLayout but the exception is because you are type casting a linear layout to AdWhirlLayout – ingsaurabh Dec 23 '10 at 13:01
0

In layout XML, the adwhirl layout should not be defined as LinearLayout, but as AdWhirlLayout.

Don't forget to add the XML namespace to the root element of the layout file:

xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"

The com.adwhirl.AdWhirlLayout element itself might be present within a LinearLayout though.

Here is a XML snippet example:

<?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
    ... other LinearLayout attributes here">

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

    ...other elements here
rolve
  • 10,083
  • 4
  • 55
  • 75
ddu
  • 1