Android AdMob Phonegap无效

时间:2012-08-08 14:08:03

标签: android android-layout cordova admob

任何人都可以帮助我,我试图在最近两天内在android中实现admob,但是收到以下错误消息 -

  

08-08 19:05:33.362:W / webcore(3228):无法获取viewWidth后   第一次布局08-08 19:10:51.632:W / dalvikvm(3328):VFY:无法   解决直接方法3204:Landroid / webkit / WebView;。   (Landroid / content / Context; Landroid / util / AttributeSet; IZ)V 08-08   19:10:51.662:I / webclipboard(3328):clipservice:   android.sec.clipboard.ClipboardExManager@40534500 08-08 19:10:52.142:   I / CordovaLog(3328):将日志级别更改为DEBUG(3)08-08 19:10:52.142:   I / CordovaLog(3328):找到useBrowserHistory = false 08-08的首选项   19:10:52.142:D / CordovaLog(3328):找到偏好   useBrowserHistory = false 08-08 19:10:52.152:E / dalvikvm(3328):可能   找不到引用自的类'android.webkit.WebResourceResponse'   方法   org.apache.cordova.CordovaWebViewClient.generateWebResourceResponse   08-08 19:10:52.152:W / dalvikvm(3328):VFY:无法解决   新实例467(Landroid / webkit / WebResourceResponse;)in   Lorg /阿帕奇/科尔多瓦/ CordovaWebViewClient; 08-08 19:10:52.152:   W / dalvikvm(3328):VFY:无法找到签名中引用的类   (Landroid / webkit / WebResourceResponse;)08-08 19:10:52.182:   W / dalvikvm(3328):VFY:无法找到签名中引用的类   (Landroid / webkit / WebResourceResponse;)08-08 19:10:52.182:   W / dalvikvm(3328):VFY:无法找到签名中引用的类   (Landroid / webkit / WebResourceResponse;)08-08 19:10:52.182:   W / dalvikvm(3328):VFY:无法解析虚方法3225:   Landroid / WebKit的/ WebViewClient; .shouldInterceptRequest   (Landroid / webkit的/ web视图; Ljava /郎/字符串;)Landroid / webkit的/ WebResourceResponse;   08-08 19:10:52.182:D / DroidGap(3328):DroidGap.init()08-08   19:10:52.192:D / CordovaWebView(3328):>>>   loadUrl(file:///android_asset/www/index.html)08-08 19:10:52.192:   D / PluginManager(3328):init()08-08 19:10:52.212:   D / CordovaWebView(3328):>>> loadUrlNow()08-08 19:10:52.272:   电子广告(3328):找不到com.google.ads.AdActivity,请制作   确定它已在AndroidManifest.xml中注册。 08-08 19:10:52.272:   E / Ads(3328):您必须在AndroidManifest.xml中声明AdActivity   使用configChanges。 08-08 19:10:52.282:I / webclipboard(3328):   clipservice:android.sec.clipboard.ClipboardExManager@405512e0 08-08   19:10:52.332:I / webclipboard(3328):clipservice:   android.sec.clipboard.ClipboardExManager@405512e0 08-08 19:10:52.902:   D / AndroidRuntime(3328):关闭VM 08-08 19:10:52.902:   W / dalvikvm(3328):threadid = 1:线程退出未捕获的异常   (组= 0x40018578)08-08 19:10:52.902:E / AndroidRuntime(3328):致命   EXCEPTION:main 08-08 19:10:52.902:E / AndroidRuntime(3328):   java.lang.RuntimeException:无法启动活动   ComponentInfo {com.ApplicationNexus.Albania / com.ApplicationNexus.Albania.Albania}:   java.lang.NullPointerException 08-08 19:10:52.902:   E / AndroidRuntime(3328):at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)   08-08 19:10:52.902:E / AndroidRuntime(3328):at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)   08-08 19:10:52.902:E / AndroidRuntime(3328):at   android.app.ActivityThread.access $ 1500(ActivityThread.java:117)08-08   19:10:52.902:E / AndroidRuntime(3328):at   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)   08-08 19:10:52.902:E / AndroidRuntime(3328):at   android.os.Handler.dispatchMessage(Handler.java:99)08-08   19:10:52.902:E / AndroidRuntime(3328):at   android.os.Looper.loop(Looper.java:130)08-08 19:10:52.902:   E / AndroidRuntime(3328):at   android.app.ActivityThread.main(ActivityThread.java:3687)08-08   19:10:52.902:E / AndroidRuntime(3328):at   java.lang.reflect.Method.invokeNative(Native Method)08-08   19:10:52.902:E / AndroidRuntime(3328):at   java.lang.reflect.Method.invoke(Method.java:507)08-08 19:10:52.902:   E / AndroidRuntime(3328):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)   08-08 19:10:52.902:E / AndroidRuntime(3328):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)08-08   19:10:52.902:E / AndroidRuntime(3328):at   dalvik.system.NativeStart.main(Native Method)08-08 19:10:52.902:   E / AndroidRuntime(3328):引起:java.lang.NullPointerException   08-08 19:10:52.902:E / AndroidRuntime(3328):at   com.ApplicationNexus.Albania.Albania.onCreate(Albania.java:22)08-08   19:10:52.902:E / AndroidRuntime(3328):at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)   08-08 19:10:52.902:E / AndroidRuntime(3328):at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)   08-08 19:10:52.902:E / AndroidRuntime(3328):... 11更多

Following is the code of my main java file -


    import org.apache.cordova.*;
    import com.google.ads.*;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.app.NavUtils;
    import android.widget.*;

    public class Albania extends DroidGap {
        private AdView adView;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");
            super.setIntegerProperty("loadUrlTimeoutValue", 70000);
            adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
            LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
            layout.addView(adView);
            adView.loadAd(new AdRequest()); }

这是我的activity_appname.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".Albania" />


    <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, S567041ba118d"
                         ads:loadAdOnCreate="true"/>


</RelativeLayout>

这是我的android manifest.xml文件

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Albania"
            android:label="@string/title_activity_albania" 
            android:configChanges="orientation|keyboardHidden|orientation|keyboard|screenSize|uiMode|screenLayout|locale"
            android:hardwareAccelerated="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> 
    <activity
        android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />         
    </application>
</manifest>

2 个答案:

答案 0 :(得分:0)

this SO question,确保您的清单xml:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>

答案 1 :(得分:0)

您无需在XML和代码中指定AdView。只需将ads:adUnitId="a1502224a0ab1f8"放入XML中的com.google.ads.AdView,即可删除以下Adview代码:

adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
layout.addView(adView);
adView.loadAd(new AdRequest());

编辑:

Cordova让您加载网址并以您设置视图的方式进行抽象。您必须手动获取Cordova WebView的父级,并将adView添加到parentView。代码可能如下所示:

adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
// Get the parent of the cordova webview. May be able to do something like: this.webView.getParent();
parentView.addView(adView);
adView.loadAd(new AdRequest());