无法实例化Smaato自定义横幅视图(Android)
我尝试在我的应用程序中使用Smaato广告。乍一看,它使用起来很简单,但实际上我遇到了一个问题。我在主视图XML中添加了Smaato横幅。第一个问题是Eclipse在GraphicLayout选项卡中向我显示下一条错误消息: * 无法实例化以下类: -com.smaato.SOMA.SOMABanner有关详细信息,请参阅错误日志窗口>显示视图。提示:在自定义视图中使用View.isInEditMode 在Eclipse中显示时跳过代码 * main.xml文件代码:无法实例化Smaato自定义横幅视图(Android),android,android-layout,android-custom-view,instantiation,Android,Android Layout,Android Custom View,Instantiation,我尝试在我的应用程序中使用Smaato广告。乍一看,它使用起来很简单,但实际上我遇到了一个问题。我在主视图XML中添加了Smaato横幅。第一个问题是Eclipse在GraphicLayout选项卡中向我显示下一条错误消息: * 无法实例化以下类: -com.smaato.SOMA.SOMABanner有关详细信息,请参阅错误日志窗口>显示视图。提示:在自定义视图中使用View.isInEditMode 在Eclipse中显示时跳过代码 * main.xml文件代码: <?xml vers
<?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>
运行程序时,引发异常:
12-20 03:00:48.415:错误/AndroidRuntime12819:致命异常:主
12-20 03:00:48.415:错误/AndroidRuntime12819:
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:错误/AndroidRuntime12819:在
android.app.ActivityThread.performLaunchActivityActivityThread.java:1821
12-20 03:00:48.415:错误/AndroidRuntime12819:在
android.app.ActivityThread.handleLaunchActivityActivityThread.java:1842
12-20 03:00:48.415:错误/AndroidRuntime12819:在
android.app.ActivityThread.access$1500ActivityThread.java:13212-20
03:00:48.415:错误/AndroidRuntime12819:在
android.app.ActivityThread$H.handleMessageActivityThread.java:1038
12-20 03:00:48.415:错误/AndroidRuntime12819:在
android.os.Handler.dispatchMessageHandler.java:99 12-20
03:00:48.415:错误/AndroidRuntime12819:在
android.os.Looper.Looper.java:143 12-20 03:00:48.415:
错误/AndroidRuntime12819:at
android.app.ActivityThread.mainActivityThread.java:4268 12-20
03:00:48.415:错误/AndroidRuntime12819:在
java.lang.reflect.Method.Invokenative方法12-20
03:00:48.415:错误/AndroidRuntime12819:在
java.lang.reflect.Method.invokeMethod.java:507 12-20 03:00:48.415:
错误/AndroidRuntime12819:at
java:839
12-20 03:00:48.415:错误/AndroidRuntime12819:在
java:59712-20
03:00:48.415:错误/AndroidRuntime12819:在
dalvik.system.NativeStart.Main本地方法12-20 03:00:48.415:
错误/AndroidRuntime12819:原因:java.lang.ClassCastException:
android.widget.TextView 12-20 03:00:48.415:
错误/AndroidRuntime12819:at
com.example.android.My.App.onCreateCommander.java:132 12-20
03:00:48.415:错误/AndroidRuntime12819:在
android.app.Instrumentation.callActivityOnCreateInstrumentation.java:1093
12-20 03:00:48.415:错误/AndroidRuntime12819:在
java:1785
12-20 03:00:48.415:错误/AndroidRuntime12819:。。。还有11个
谁知道问题出在哪里?我需要做什么来修复它?有人和Smaato一起工作吗?
使用Smaato SDK 2.5.4版它显示您在命令类中的第132行获得ClassCastException
请发布Commander类的onCreate方法或查看onCreate方法中的TextView强制转换。以下是对我有效的解决方案: -在eclipse中,右键单击项目->属性->Java构建路径->订单和导出
检查路径中的SOMA jar文件,然后立即尝试 我将Smaato jar复制到libs/目录中;这似乎有帮助
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);