我尝试在我的应用中使用Smaato广告。首先看它使用起来很简单,但实际上我遇到了问题。我在主视图中放入了一个Smaato横幅。第一个问题是Eclipse在GraphicLayout选项卡中向我显示下一条错误消息: *
无法实例化以下类: - com.smaato.SOMA.SOMABanner有关详细信息,请参阅错误日志(窗口>显示视图)。提示:在自定义视图中使用View.isInEditMode() 在Eclipse中显示时跳过代码
* main.xml文件代码:
<?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开发人员指南: 1)我在我的应用程序中定义了一个横幅视图(如上所述)
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);
当我运行程序时,抛出异常:
12-20 03:00:48.415:ERROR / AndroidRuntime(12819):致命异常:主要 12-20 03: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(12819):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: 错误/ 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: 错误/ 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: ERROR / AndroidRuntime(12819):引起:java.lang.ClassCastException: android.widget.TextView 12-20 03:00:48.415: 错误/ AndroidRuntime(12819):at 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):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 12-20 03:00:48.415:ERROR / AndroidRuntime(12819):... 11更多
谁知道这是什么问题?我需要做些什么来解决它?任何机构都与Smaato合作? 使用Smaato SDK版本2.5.4
答案 0 :(得分:0)
它显示您在第132行的Commander类中获得了ClassCastException。
请发布您的Commander类的onCreate方法或查看onCreate方法中的TextView强制转换。
答案 1 :(得分:0)
以下解决方案对我有用: - 在eclipse中,右键单击项目 - &gt;属性 - &gt; Java构建路径 - &gt;订单和出口 检查路径中的SOMA jar文件,立即尝试!
答案 2 :(得分:0)
我将Smaato jar复制到libs /目录中;这似乎有所帮助。