Reputation: 215
I have tried everything that i can find on the net to resolved this issue. All i want is to play the ad once the activity starts but keep getting this error message.i have removed and added it couple of time as advised by many post but no luck. Could someone please help me with this. I have added the google.play.service.libs as a android code---> marked it as a library-->went to my project properties to reference it--> cleaned both project --RUn (ERROR)
07-10 10:40:40.519: W/dalvikvm(31206): threadid=1: thread exiting with uncaught exception (group=0x40dc8ac8) 07-10 10:40:40.529: E/AndroidRuntime(31206): FATAL EXCEPTION: main 07-10 10:40:40.529: E/AndroidRuntime(31206): java.lang.NoClassDefFoundError: com.google.android.gms.ads.InterstitialAd 07-10 10:40:40.529: E/AndroidRuntime(31206): at com.multiinspection5.Profile.onCreate(Profile.java:41) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.Activity.performCreate(Activity.java:5250) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.ActivityThread.access$700(ActivityThread.java:152) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.os.Handler.dispatchMessage(Handler.java:99) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.os.Looper.loop(Looper.java:137) 07-10 10:40:40.529: E/AndroidRuntime(31206): at android.app.ActivityThread.main(ActivityThread.java:5328) 07-10 10:40:40.529: E/AndroidRuntime(31206): at java.lang.reflect.Method.invokeNative(Native Method) 07-10 10:40:40.529: E/AndroidRuntime(31206): at java.lang.reflect.Method.invoke(Method.java:511) 07-10 10:40:40.529: E/AndroidRuntime(31206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 07-10 10:40:40.529: E/AndroidRuntime(31206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 07-10 10:40:40.529: E/AndroidRuntime(31206): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 2133
Reputation: 521
You also have to reference the google-play-services.jar in your project. You can find it in the "libs" folder at the google-play-services-lib project.
Upvotes: 1
Reputation: 790
Try this code:-
public void loadad(){
this.interstitialAds = new InterstitialAd(this, "Publisher_Id");
AdRequest adr = new AdRequest();
// add your test device here
//adr.addTestDevice("8E452640BC83C672B070CDCA8AB9B06B");
interstitialAds.loadAd(adr);
this.interstitialAds.setAdListener(new AdListener() {
@Override
public void onReceiveAd(Ad arg0) {
// TODO Auto-generated method stub
if (interstitialAds.isReady()) {
interstitialAds.show();
} else {
}
}
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode error) {
// TODO Auto-generated method stub
String message = "Load Ads Failed: (" + error + ")";
}
@Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
int DELAY = 120000;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Intent intent = new Intent(Home.this, MainActivity.class);
// startActivity(intent);
loadad();
}
}, DELAY);
}
@Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
});
}
Use this code and call on starting of your app. And there is a Handler inside onDismissScreen(). If you want call this after few minutes..
Upvotes: 0