0

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)

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
Ahsan
  • 195
  • 1
  • 20

2 Answers2

1

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.

JoniDS
  • 511
  • 4
  • 7
  • i tried that and it didn't work. It is recommended to not do that as ADT looks for it under under Android Dependencies but i still tried – Ahsan Jul 10 '14 at 14:41
  • I don't think it's related but did you add the "AdActivity" to your app manifest? – JoniDS Jul 10 '14 at 15:05
  • If you are using gradle you don't need to include the lib, just add "compile 'com.google.android.gms:play-services:+' to your dependencies – JoniDS Jul 10 '14 at 15:23
0

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..

Laxmeena
  • 780
  • 2
  • 7
  • 28
  • Thanks Rajeev but this code is giving me problems regarding importing. I am a newbie with this so apologize if i can't get it right away. This seems like a work around. Wondering if there is a actual fix for this issue – Ahsan Jul 10 '14 at 14:27
  • @Ahsan, Just import the google play liberary. which types of errors you are getting. please post here.. – Laxmeena Jul 10 '14 at 14:33
  • i have posted my logcat...java.lang.NoClassDefFoundError: com.google.android.gms.ads.InterstitialAd – Ahsan Jul 10 '14 at 14:42