广告暴徒阻止应用程序在牛轧糖模拟器上启动

时间:2017-02-11 20:09:28

标签: android admob

将admob添加到我的应用程序后,它在kitkat模拟器和真正的移动设备上运行良好,但在牛轧糖模拟器上测试时失败。提前感谢

app screenshot jpg

Adding ad mob code and steps

这是启动应用程序时出现的logcat

package com.wEgyptianpost;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.TextView;

import java.util.Random;

import com.google.android.gms.ads.AdRequest;

import com.google.android.gms.ads.AdView;

import com.wEgyptianpost.R;


public class MainActivity extends Activity {
    WebView view;
    SwipeRefreshLayout mySwipeRefreshLayout;

    private WebView mWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AdView adView = (AdView) findViewById(R.id.admob_id);

        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();

        adView.loadAd(adRequest);



        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipelayout);
        final WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);
        swipeRefreshLayout.setColorSchemeResources(R.color.refresh,R.color.refresh1,R.color.refresh2);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mWebView.reload();
                swipeRefreshLayout.setRefreshing(true);
                (new Handler()).postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mWebView.stopLoading();
                        swipeRefreshLayout.setRefreshing(false);





                    }
                },10000);
            }
        });
        // Force links and redirects to open in the WebView instead of in a browser
        //mWebView.setWebViewClient(new WebViewClient());

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        // Use remote resource
         mWebView.loadUrl("http:google.com");

        // Stop local links and redirects from opening in browser instead of WebView
         mWebView.setWebViewClient(new MyAppWebViewClient());

        // Use local resource
        //mWebView.loadUrl("file:android_asset/web/google.html");


    }



    // Prevent the back-button from closing the app
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }



}

这是主要的活动代码,第37行有什么问题? (这是广告请求行)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity">


    <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">
        <WebView
            android:id="@+id/activity_main_webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />


        <ScrollView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">

   </ScrollView>


</android.support.v4.widget.SwipeRefreshLayout >

    <com.google.android.gms.ads.AdView android:id="@+id/admob_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-1851250777225639/8300259410"
        android:layout_gravity="center_horizontal|bottom" />




</FrameLayout>

这是我的活动xml

from __future__ import division # For Python 2.7
import pygame

pygame.init()
screen = pygame.display.set_mode((400, 400))

CENTER = (200, 200)
RADIUS = 100

satelliteCenter = (CENTER[0]+RADIUS, CENTER[1])

running = True
while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT: running = False

  mouse = pygame.mouse.get_pos()
  vector = (mouse[0]-CENTER[0], mouse[1]-CENTER[1])
  distance = (vector[0]**2 + vector[1]**2)**0.5

  if distance > 0:
    scalar = RADIUS / distance
    satelliteCenter = (
      int(round( CENTER[0] + vector[0]*scalar )),
      int(round( CENTER[1] + vector[1]*scalar )) )

  screen.fill((152,206,231))
  pygame.draw.circle(screen, (71,153,192), CENTER, RADIUS)
  pygame.draw.circle(screen, (243,79,79), satelliteCenter, 16)
  pygame.display.update()

2 个答案:

答案 0 :(得分:0)

MainActivity第37行出现故障。 它在一个null的引用上调用loadAd()

这意味着您的admob_id布局中没有名为activity_main的元素。但我们无法确认,因为您没有粘贴布局xml。

答案 1 :(得分:0)

有两个活动xml文件,我在这里写的一个叫做activity.xml,另一个在app下面叫做#34; v23 / activity.xml&#34; ..我右键点击了这个v23 /activity.xml文件,从出现的列表我选择了文件路径,我删除了它的文件。之后我在Nougat上尝试了应用程序,最后它运行了。