0

我試圖在我的應用中使用Smaato廣告。首先看它使用起來很簡單,但實際上我遇到了一個問題。我在主視圖中放入了一個Smaato橫幅。問題一處於了Eclipse顯示我在GraphicLayout選項卡下一個錯誤信息: *Smaato自定義橫幅視圖無法實例化(Android)

以下類不能被實例化: - com.smaato.SOMA.SOMABanner看到錯誤日誌(窗口>顯示查看)瞭解更多詳情。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RootLayout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.smaato.SOMA.SOMABanner 
    android:id="@+id/bannerView" 
    android:layout_width="fill_parent"    
    android:layout_height="90dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    /> 
</LinearLayout> 

因此官方SOMA SDK開發人員指南:提示:在Eclipse中所示

* 的main.xml文件的代碼時使用View.isInEditMode()在您的自定義視圖 跳躍代碼 1)I定義在我的申請的橫幅視圖(如上所述)

2)在代碼我manully添加到onCreate方法:

SOMABanner mBanner = (SOMABanner)findViewById(R.id.BannerView); 
//In order to fetch live ads inside the activity, add your PublisherID and AdspaceID in the 
//onCreate method. For example: 
mBanner.setPublisherId(my_publisher_id); 
mBanner.setAdSpaceId(my_adspace_id); 

當我跑了PROGRAMM,拋出異常:

3月12日至20日:00:48.415:ERROR/AndroidRuntime(12819):致命異常:主 3月12日至20日:00:48.415:ERROR/AndroidRuntime(12819): java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.example.android.My/com.example.android.My.App}: java.lang.ClassCastException:android.widget。 TextView 12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821) 12-20 03:00:48.415:ERROR/AndroidRuntime(1281 9):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842) 12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.app.ActivityThread.access $ 1500(ActivityThread.java :132)12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1038) 12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.os.Handler.dispatchMessage(Handler.java:99)12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.os.Looper.loop(Looper。 java:143)12-20 03:00:48.415: ERROR/AndroidRuntime(12819):at android.app.ActivityThread.main(ActivityThread.java:4268)12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at java.lang.reflect.Method.invokeNative(Native Method)12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at java。 lang.reflect.Method.invoke(Method.java:507)12-20 03:00:48.415: ERROR/AndroidRuntime(12819):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java :839) 12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)12-20 03:00:48.415: ERROR/AndroidRuntime(12819):at dalvik.system.NativeStart.main(Native Method)12-20 03:00:48.415: 錯誤/ AndroidRuntime(12819):由:java.lang.ClassCastException引起: android.widget.TextView 12-20 03:00:48.415: 錯誤/ AndroidRuntime(12819):在 com.example.android.My.App.onCreate(Commander。java:132)12-20 03:00:48.415:ERROR/AndroidRuntime(12819):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 12-20 03:00:48.415:ERROR/AndroidRuntime (12819):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 3月12日至20日:00:48.415:ERROR/AndroidRuntime(12819):...... 11多個

誰知道問題是什麼?我需要做什麼來解決它?任何機構都可以與Smaato合作? 使用的Smaato SDK版本2.5.4

回答

0

它顯示您在第132行的Commander類中出現ClassCastException。

請發佈您的Commander類的onCreate方法或查看TextView在onCreate方法中的強制轉換。

0

這裏是爲我工作的解決方案: - 在Eclipse中,右鍵單擊項目 - >屬性 - > Java構建路徑 - >在線訂單和出口 檢查SOMA jar文件的路徑和現在就來試試!

0

我將Smaato jar複製到libs /目錄中;這似乎有幫助。

相關問題