Adwhirl 导致我的 Android 应用程序崩溃?

发布于 2024-10-31 10:31:52 字数 6497 浏览 5 评论 0原文

我的应用程序有一个非常简单的设置,以便测试 adwhirl

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.adwhirl.AdWhirlLayout;

public class testads extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testads);

        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
        AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my_ADWHIRLSDKCODE");
        RelativeLayout.LayoutParams adWhirlLayoutParams =
                new RelativeLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        layout.addView(adWhirlLayout, adWhirlLayoutParams);
        layout.invalidate();
    }
}

,布局文件如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/layout_main"
  >
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <AdWhirlLayout android:id="@+id/adwhirl_layout"/>
</LinearLayout>

当我运行它时,应用程序崩溃...这应该很简单,我做错了什么?

编辑:很抱歉我之前没有包含日志错误...这里是

04-11 17:21:36.215: ERROR/AndroidRuntime(2084): FATAL EXCEPTION: main
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vicvic.android/com.vicvic.android.testads}: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.os.Looper.loop(Looper.java:123)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.reflect.Method.invokeNative(Native Method)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.reflect.Method.invoke(Method.java:521)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at dalvik.system.NativeStart.main(Native Method)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.Activity.setContentView(Activity.java:1647)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.vicvic.android.testads.onCreate(testads.java:18)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     ... 11 more
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: java.lang.ClassNotFoundException: android.view.AdWhirlLayout in loader dalvik.system.PathClassLoader[/data/app/com.vicvic.android-2.apk]
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createView(LayoutInflater.java:466)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     ... 20 more
04-11 17:21:36.375: WARN/ActivityManager(66):   Force finishing activity com.vicvic.android/.testads
04-11 17:21:36.895: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads}
04-11 17:21:42.635: DEBUG/dalvikvm(185): GC_EXPLICIT freed 149 objects / 10872 bytes in 86ms
04-11 17:21:47.308: WARN/ActivityManager(66): Activity destroy timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads}
04-11 17:21:47.735: DEBUG/dalvikvm(267): GC_EXPLICIT freed 31 objects / 1400 bytes in 178ms
04-11 17:22:29.135: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol

i have a very simple setup for my app in order to test adwhirl

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.adwhirl.AdWhirlLayout;

public class testads extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testads);

        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
        AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my_ADWHIRLSDKCODE");
        RelativeLayout.LayoutParams adWhirlLayoutParams =
                new RelativeLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        layout.addView(adWhirlLayout, adWhirlLayoutParams);
        layout.invalidate();
    }
}

and the layout file is as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/layout_main"
  >
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <AdWhirlLayout android:id="@+id/adwhirl_layout"/>
</LinearLayout>

When i run it, the app crashes... This should be so simple, what am i doing wrong?

edit: i am sorry i did not include the log error before... here it is

04-11 17:21:36.215: ERROR/AndroidRuntime(2084): FATAL EXCEPTION: main
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vicvic.android/com.vicvic.android.testads}: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.os.Looper.loop(Looper.java:123)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.reflect.Method.invokeNative(Native Method)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.reflect.Method.invoke(Method.java:521)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at dalvik.system.NativeStart.main(Native Method)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.Activity.setContentView(Activity.java:1647)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.vicvic.android.testads.onCreate(testads.java:18)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     ... 11 more
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: java.lang.ClassNotFoundException: android.view.AdWhirlLayout in loader dalvik.system.PathClassLoader[/data/app/com.vicvic.android-2.apk]
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createView(LayoutInflater.java:466)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):     ... 20 more
04-11 17:21:36.375: WARN/ActivityManager(66):   Force finishing activity com.vicvic.android/.testads
04-11 17:21:36.895: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads}
04-11 17:21:42.635: DEBUG/dalvikvm(185): GC_EXPLICIT freed 149 objects / 10872 bytes in 86ms
04-11 17:21:47.308: WARN/ActivityManager(66): Activity destroy timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads}
04-11 17:21:47.735: DEBUG/dalvikvm(267): GC_EXPLICIT freed 31 objects / 1400 bytes in 178ms
04-11 17:22:29.135: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他夏了夏天 2024-11-07 10:31:52

如果没有错误消息,它只是猜测。
尝试类似的东西
XML 中的 使用 AdWhirlLayout-Class 的包名称

Without an error message it's just guessing.
Try something like
<com.adwhirl.AdWhirlLayout> in your XML using the package name of the AdWhirlLayout-Class

無心 2024-11-07 10:31:52

如果没有 logcat 中的错误,我们只能猜测:

您已在 xml 中定义了 AdWhirlLayout,但在 onCreate 中创建了一个新布局。我想您还应该为您的 adwhirlllayout 使用 findViewById ,并且您不应该将其添加到您的layout_main中,因为它已经在那里了。

这只是一个猜测,因为您没有提供错误消息...

编辑:您应该决定:您是在 xml 中布局(而不是遵循 @Hache 所说的)还是在 onCreate 中进行布局。不要尝试混合使用两种方式,尤其是不要两次添加相同的视图(一次在 xml 中,一次在 onCreate 中)

Without the error from your logcat we can only guess:

You have defined AdWhirlLayout in your xml but you create a new one in your onCreate. I guess you should also use findViewById for your adwhirllayout and you shouldn't add it to your layout_main, because it is already there.

Thats just a guess because you didn't provide an error message...

edit: You should decide: Do you layout in xml (than follow what @Hache has said) or do it in onCreate. Don't try to mix both ways, especially not adding the same view twice (once in xml, once in onCreate)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文