首页 > 解决方案 > 插页式广告未在 android studio 中运行

问题描述

我尝试使用 android studio 在我的应用程序中添加广告,但是在我运行它时完成代码后,应用程序崩溃了。我在下面附上了错误代码。

拜托,有人可以调查一下并帮助我吗?

代码:

package com.divesh.sliderapp;

import android.content.Intent;

import android.graphics.Typeface;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.firebase.client.Firebase;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

public class Information extends AppCompatActivity {

    Button Bd;
    RadioButton rtez;
    RadioButton rpaytm;
    RadioButton rrecharge;
    RadioButton r5;
    RadioButton r10;
    RadioButton r15;
    private Firebase mRootRef;
    EditText mname;
    EditText memail;
    EditText mnumber;
    EditText mcountry;
    RadioGroup r1;
    RadioGroup r2;
    TextView text;
    String days;
    String mplatform;

    private InterstitialAd minterstitial;


    private AdView adView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);



        mRootRef = new Firebase("https://rewards-converter.firebaseio.com/Users");


        MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

        minterstitial = new InterstitialAd(this);
        minterstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
        minterstitial.loadAd(new AdRequest.Builder().build());

        minterstitial.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                // Load the next interstitial.
                minterstitial.loadAd(new AdRequest.Builder().build());
            }

        });


        mname = (EditText) findViewById(R.id.name);

        mcountry = (EditText) findViewById(R.id.counry);
        memail = (EditText) findViewById(R.id.email);
        mnumber = (EditText) findViewById(R.id.number);

        text = (TextView) findViewById(R.id.t0);

        days="5";
        mplatform="paytm";

        rpaytm = (RadioButton) findViewById(R.id.paytm);
        rrecharge = (RadioButton) findViewById(R.id.recharge);
        rtez = (RadioButton) findViewById(R.id.googlepay);
        r5 = (RadioButton) findViewById(R.id.five);
        r10 = (RadioButton) findViewById(R.id.ten);
        r15 = (RadioButton) findViewById(R.id.fifteen);
        Typeface font5 = Typeface.createFromAsset(this.getAssets(), "Fonts/Raleway-Medium.ttf");
        mname.setTypeface(font5);
        memail.setTypeface(font5);
        mcountry.setTypeface(font5);
        mnumber.setTypeface(font5);
        rpaytm.setTypeface(font5);
        rrecharge.setTypeface(font5);
        rtez.setTypeface(font5);
        r5.setTypeface(font5);
        r10.setTypeface(font5);
        r15.setTypeface(font5);
        r1 = (RadioGroup) findViewById(R.id.radioGroup1);
        r2 = (RadioGroup) findViewById(R.id.RadioGroup2);

        int selectedId = r1.getCheckedRadioButtonId();
        int selectedid2 = r2.getCheckedRadioButtonId();

        rpaytm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mplatform = "paytm";
            }
        });


        rtez.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mplatform = "tez";
            }
        });


        rrecharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mplatform = "recharge";
            }
        });

        r10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                text.setText("You Will Recieve Your Amount Within 10 Working Days But With Reduction Of 45% Which Include Tax By Google And Our Conversion Charges");
                days = "10";
            }
        });

        r5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                text.setText("You Will Recieve Your Amount Within 5 Working Days But With Reduction Of 50% Which Include Tax By Google And Our Conversion Charges");
                days = "5";
            }
        });

        r15.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                text.setText("You Will Recieve Your Amount Within 15 Working Days But With Reduction Of 40% Which Include Tax By Google And Our Conversion Charges");
                days = "15";
            }
        });

        Typeface font = Typeface.createFromAsset(this.getAssets(), "Fonts/KoHo-Bold.ttf");
        text.setTypeface(font);






        Bd = (Button) findViewById(R.id.proceed);
        Bd.setTypeface(font5);
        Bd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if(minterstitial.isLoaded()){
                    minterstitial.show();
                }
                else{
                    Log.d("TAG","intertestial add not loaded");
                }


                String name = mname.getText().toString();
                String email = memail.getText().toString();
                String number = mnumber.getText().toString();
                String country = mcountry.getText().toString();


                Intent i = new Intent(Information.this, payment.class);
                i.putExtra("name",name);
                i.putExtra("email",email);
                i.putExtra("platform",mplatform);
                i.putExtra("number",number);
                i.putExtra("Days",days);
                i.putExtra("Country",country);



                startActivity(i);
                finish();
           }
        });

    }



}

错误:

11-06 21:57:21.292 15787-15787/com.divesh.sliderapp E/AndroidRuntime:致命异常:主进程:com.divesh.sliderapp,PID:15787 java.lang.NoClassDefFoundError:解析失败:Lcom/google/安卓/gms/动态/zzp;在 com.google.android.gms.internal.zzkb.zzib(未知来源:0) 在 com.google.android.gms.internal.zzly.zza(未知来源:19) 在 com.google.android.gms.ads .MobileAds.initialize(Unknown Source:12) at com.google.android.gms.ads.MobileAds.initialize(Unknown Source:1) at com.divesh.sliderapp.Information.onCreate(Information.java:59) at android。 app.Activity.performCreate(Activity.java:7023) 在 android.app.Activity.performCreate(Activity.java:7014) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:

构建 Gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.divesh.sliderapp"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 31
        versionName "1.9"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.firebase:firebase-client-android:2.3.1'
    implementation 'com.google.firebase:firebase-database:16.0.3'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:17.0.0'

}
apply plugin: 'com.google.gms.google-services'

标签: androidandroid-studioerror-handling

解决方案


推荐阅读