Reputation: 62
The following classes could not be instantiated: - com.google.android.gms.ads.AdView (Open Class, Show Error Log) : AdMob
I have followed the steps(copy and pasted it as it is) given in the documentation at developers admob site. and have implemented their example in eclipse ADT. It still not working..and the application stops unexpectedly.
here is the activity_main.xml
<RelativeLayout 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="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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
-----MainActivity.java-----
package com.google.android.gms.example;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
--Manifest File--
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.example.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>
--Error Log--
eclipse.buildId=v22.0.5-757759
java.version=1.8.0_31
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -product com.android.ide.eclipse.adt.package.product
Command-line arguments: -os win32 -ws win32 -arch x86 -product com.android.ide.eclipse.adt.package.product
Error
Sun Jun 14 17:13:05 IST 2015
No command output when running: 'am start -n com.google.android.gms.example/com.google.android.gms.example.MainActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER' on device emulator-5554
com.android.ddmlib.ShellCommandUnresponsiveException
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:408)
at com.android.ddmlib.Device.executeShellCommand(Device.java:435)
at com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction( ActivityLaunchAction.java:67)
at com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction( ActivityLaunchAction.java:109)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.doLaunchActi on(AndroidLaunchController.java:1286)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.doLaunchActi on(AndroidLaunchController.java:1298)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launchApp(An droidLaunchController.java:1270)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.simpleLaunch (AndroidLaunchController.java:906)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.continueLaun ch(AndroidLaunchController.java:748)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(AndroidLaunchController.java:570)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.doLaunch(Launch ConfigDelegate.java:322)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchCo nfigDelegate.java:238)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.j ava:855)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.j ava:704)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:10 47)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
--logcat--
06-14 08:06:11.481: E/dalvikvm(1168): Could not find class 'com.google.android.gms.ads.AdView', referenced from method com.google.android.gms.example.MainActivity.onCreate
06-14 08:06:11.481: W/dalvikvm(1168): VFY: unable to resolve check-cast 639 (Lcom/google/android/gms/ads/AdView;) in Lcom/google/android/gms/example/MainActivity;
06-14 08:06:11.491: D/dalvikvm(1168): VFY: replacing opcode 0x1f at 0x000f
06-14 08:06:11.531: D/dalvikvm(1168): DexOpt: unable to opt direct call 0x120d at 0x13 in Lcom/google/android/gms/example/MainActivity;.onCreate
06-14 08:06:12.562: D/AndroidRuntime(1168): Shutting down VM
06-14 08:06:12.562: W/dalvikvm(1168): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
06-14 08:06:12.761: E/AndroidRuntime(1168): FATAL EXCEPTION: main
06-14 08:06:12.761: E/AndroidRuntime(1168): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms.example/com.google.android.gms.example.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.google.android.gms.ads.AdView
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.os.Looper.loop(Looper.java:137)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread.main(ActivityThread.java:5103)
06-14 08:06:12.761: E/AndroidRuntime(1168): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 08:06:12.761: E/AndroidRuntime(1168): at java.lang.reflect.Method.invoke(Method.java:525)
06-14 08:06:12.761: E/AndroidRuntime(1168): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
06-14 08:06:12.761: E/AndroidRuntime(1168): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-14 08:06:12.761: E/AndroidRuntime(1168): at dalvik.system.NativeStart.main(Native Method)
06-14 08:06:12.761: E/AndroidRuntime(1168): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.google.android.gms.ads.AdView
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-14 08:06:12.761: E/AndroidRuntime(1168): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.Activity.setContentView(Activity.java:1895)
06-14 08:06:12.761: E/AndroidRuntime(1168): at com.google.android.gms.example.MainActivity.onCreate(MainActivity.java:14)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.Activity.performCreate(Activity.java:5133)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
06-14 08:06:12.761: E/AndroidRuntime(1168): ... 11 more
06-14 08:06:12.761: E/AndroidRuntime(1168): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: DexPathList[[zip file "/data/app/com.google.android.gms.example-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gms.example-1, /system/lib]]
06-14 08:06:12.761: E/AndroidRuntime(1168): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
06-14 08:06:12.761: E/AndroidRuntime(1168): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-14 08:06:12.761: E/AndroidRuntime(1168): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
06-14 08:06:12.761: E/AndroidRuntime(1168): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
06-14 08:06:12.761: E/AndroidRuntime(1168): ... 21 more
Upvotes: 0
Views: 1009
Reputation: 62
Edit(Answer):
Thank you for all the answer. I appreciate it.
I Came to know about the actual problem, the Eclipse ADT was not updated and hence the error was there but after the update, it was still not working hence I switched to Android Studio and the code is now working as expected.
Thank You All
Upvotes: 0
Reputation: 15155
Your code should work, there's no problem. I think, you did not integrate your project with the library provided by Google. This post may helps you a lot:
https://developers.google.com/admob/android/eclipse#include_the_google_play_services_library
Please follow the steps thoroughly.
Upvotes: 3
Reputation: 4649
ShellCommandUnresponsiveException
thrown when a shell command executed on a device takes too long to send its output.
The command may not actually be unresponsive, it just has spent too much time not outputting any thing to the console. So this problem is not related to your code.
Upvotes: 1
Reputation: 787
Get your own google play service from your adt-bundle-windows-x86-20130514\sdk\extras\google. this will work defiantly.
Upvotes: 1
Reputation: 1809
Have you imported Google Play services lib as a project?
It's important to import google-play-services_lib as a project:
Select File > Import > Android > Existing Android Code Into Workspace
and click Next.
Select Browse..., enter
[android-sdk-folder]/extras/google/google_play_services/libproject/google-play-services_lib
, and click Finish.
(See https://developers.google.com/maps/documentation/android/intro under "Sample Code")
Then follow the instructions from the linked answer:
Import the actual source for the "google-play-services_lib" project and link it as an >Android library.
Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
Upvotes: 2