我试图使用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 / Android运行时:致命异常:主要 流程:com.divesh.sliderapp,PID:15787 java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / dynamic / zzp; 在com.google.android.gms.internal.zzkb.zzib处(未知来源:0) 在com.google.android.gms.internal.zzly.zza(未知来源:19) com.google.android.gms.ads.MobileAds.initialize上(未知来源:12) 位于com.google.android.gms.ads.MobileAds.initialize(未知来源:1) 在com.divesh.sliderapp.Information.onCreate(Information.java:59) 在android.app.Activity.performCreate(Activity.java:7023) 在android.app.Activity.performCreate(Activity.java:7014) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870) 在android.app.ActivityThread.-wrap11(未知来源:0) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1601) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:172) 在android.app.ActivityThread.main(ActivityThread.java:6590) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 由以下原因引起:java.lang.ClassNotFoundException:在路径:DexPathList [[zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ== /base.apk”、zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_dependencies_apk.apk”和zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67_apss_aps_aps_aps_apss_resource_aps_resources ”,zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_slice_0_apk.apk”、zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1X_ap_k_==。 zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_slice_2_apk.apk”,zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==//sp3_ap_sap”,zip文件。 app / com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ == / split_lib_slice_4_apk.apk”,zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==//split_lib_slice_5”。 divesh.sliderapp-L N7KgxuGw74Yh67FB1XKaQ == / split_lib_slice_6_apk.apk “zip文件 ”/data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_slice_7_apk.apk“,zip文件” /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/ split_lib_slice_8_apk.apk“,zip文件“ /data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_slice_9_apk.apk”],nativeLibraryDirectories=[/data/app/com.diveshKYbX74YKlibX-Kaiderx-Kaiderx-KiderQ-Kas=64 ,/ system / lib64,/ system / vendor / lib64]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) 在java.lang.ClassLoader.loadClass(ClassLoader.java:379) 在java.lang.ClassLoader.loadClass(ClassLoader.java:312) 在com.google.android.gms.internal.zzkb.zzib处(未知来源:0) 在com.google.android.gms.internal.zzly.zza(未知来源:19) com.google.android.gms.ads.MobileAds.initialize上(未知来源:12) 位于com.google.android.gms.ads.MobileAds.initialize(未知来源:1) 在com.divesh.sliderapp.Information.onCreate(Information.java:59) 在android.app.Activity.performCreate(Activity.java:7023) 在android.app.Activity.performCreate(Activity.java:7014) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870) 在android.app.ActivityThread.-wrap11(未知来源:0) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1601) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:172) 在android.app.ActivityThread.main(ActivityThread.java:6590) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 禁止:java.io.IOException:找不到用于dex位置/data/app/com.divesh.sliderapp-LN7KgxuGw74Yh67FB1XKaQ==/split_lib_resources_apk.apk的原始dex文件 在dalvik.system.DexFile.openDexFileNative(本机方法) 在dalvik.system.DexFile.openDexFile(DexFile.java:353) 在dalvik.system.DexFile。(DexFile.java:100) 在dalvik.system.DexFile。(DexFile.java:74) 在dalvik.system.DexPathList.loadDexFile(DexPathList.java:374) 在dalvik.system.DexPathList.makeDexElements(DexPathList.java:337) 在dalvik.system.DexPathList。(DexPathList.java:157) 在dalvik.system.BaseDexClassLoader。(BaseDexClassLoader.java:65) 在dalvik.system.PathClassLoader。(PathClassLoader.java:64) 在com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73) 在com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88) 在android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69) 11-06 21:57:21.293 15787-15787 / com.divesh.sliderapp E / AndroidRuntime:在android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:35) 在android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:683) 在android.app.LoadedApk.getClassLoader(LoadedApk.java:717) 在android.app.LoadedApk.getResources(LoadedApk.java:944) 在android.app.ContextImpl.createAppContext(ContextImpl.java:2270) 在android.app.ActivityThread.handleBindApplication(ActivityThread.java:5675) 在android.app.ActivityThread.-wrap1(未知来源:0) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1668) ...还有6个
构建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'