Smaato 自定义横幅视图无法实例化 (Android)
我尝试在我的应用程序中使用 Smaato 广告。乍一看使用起来很简单,但在实践中我遇到了问题。我在主视图 XML 中放入了 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)在代码中我手动添加到 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: 错误/AndroidRuntime(12819): 致命异常: main 12-20 03:00:48.415: 错误/AndroidRuntime(12819): java.lang.RuntimeException:无法启动活动 组件信息{com.example.android.My/com.example.android.My.App}: java.lang.ClassCastException:android.widget.TextView 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.ActivityThread.access$1500(ActivityThread.java:132) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.os.Handler.dispatchMessage(Handler.java:99) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.os.Looper.loop(Looper.java:143) 12-20 03:00:48.415: 错误/Android运行时(12819):位于 android.app.ActivityThread.main(ActivityThread.java:4268) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 java.lang.reflect.Method.invokeNative(本机方法) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 java.lang.reflect.Method.invoke(Method.java:507) 12-20 03:00:48.415: 错误/Android运行时(12819):位于 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 dalvik.system.NativeStart.main(本机方法) 12-20 03:00:48.415: 错误/AndroidRuntime(12819):由以下原因引起:java.lang.ClassCastException: android.widget.TextView 12-20 03:00:48.415: 错误/Android运行时(12819):位于 com.example.android.My.App.onCreate(Commander.java:132) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 12-20 03:00:48.415: 错误/AndroidRuntime(12819): ... 11 更多
谁知道问题是什么?我需要做什么来修复它?有任何身体可以与 Smaato 配合使用吗? 使用 Smaato SDK 版本 2.5.4
I tried to use Smaato ad in my app. For first look it's simple to use, but in practice I got a problem. I put in main view XML a Smaato banner. The problem number one is that Eclipse shows me in GraphicLayout tab the next error message:
*
The following classes could not be instantiated:
- com.smaato.SOMA.SOMABanner See the Error Log (Window > Show View) for more details. Tip: Use View.isInEditMode() in your custom views to
skip code when shown in Eclipse
*
main.xml file code:
<?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>
Accordingly to official SOMA SDK Developer guide:
1) I defined a banner view in my application (described above)
2) In code I add manully to onCreate method:
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);
When I ran a programm, throws an exception:
12-20 03:00:48.415: ERROR/AndroidRuntime(12819): FATAL EXCEPTION: main
12-20 03:00:48.415: ERROR/AndroidRuntime(12819):
java.lang.RuntimeException: Unable to start activity
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:
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:
ERROR/AndroidRuntime(12819): Caused by: java.lang.ClassCastException:
android.widget.TextView 12-20 03:00:48.415:
ERROR/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 more
Who knows what is the problem? What I need to do to fix it? Any body works with Smaato?
Used Smaato SDK version 2.5.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它显示您在 Commander 类的第 #132 行处收到了 ClassCastException。
请发布 Commander 类的 onCreate 方法或查看 onCreate 方法中的 TextView 转换。
It shows you get a ClassCastException in your Commander class at line #132.
Please post the onCreate method of your Commander class or look into TextView casts in onCreate method.
这是对我有用的解决方案:
- 在eclipse中,右键单击项目->属性-> Java 构建路径 ->订单与出口
检查路径中的 SOMA jar 文件并立即尝试!
Here is the solution what worked for me :
- In eclipse, right click on the project-> properties -> Java Build Path -> Order and Export
Check the SOMA jar file in the path and try now !
我将 Smaato jar 复制到 libs/ 目录中;这似乎有帮助。
I copied the Smaato jar into the libs/ directory; that seemed to help.