0

アプリで初めて Adwhirl を使用していますが、喜びはありません。Adwhirl はこのデモ コードを提供しましたが、以下の選択した行で「java.lang.ClassCastException: android.widget.LinearLayout」というエラーが表示されます。

    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はこちら

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

ありがとう

4

2 に答える 2

0

この行を

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

LinearLayout adWhirlLayout = (LinearLayout ) findViewById(R.id.layout_ad);
于 2010-12-16T09:50:23.333 に答える
0

レイアウト XML では、adwhirl レイアウトをLinearLayoutではなく として定義する必要がありますAdWhirlLayout

XML 名前空間をレイアウト ファイルのルート要素に追加することを忘れないでください。

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

com.adwhirl.AdWhirlLayout要素自体は、ただし内に存在する場合がありLinearLayoutます。

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
    ... 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
于 2011-05-21T11:34:30.600 に答える