The following classes cannot be created: com.google.ads.AdView
I found several questions about this problem, but I could not find a solution for this.
I added this code to my AndroidManifest.xml file:
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
and I added the GoogleAdMobAdsSdk-6.4.1.jar file to the library file.
Also I added this code at the top of my xml page:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
but it didn't work, it gives me this error message:
The following classes could not be instantiated:
- com.google.ads.AdView
and when i test the app on my phone it doesn't work.
source to share
I am assuming you installed google play service from sdk manager. Now add below code to manifest file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" ></uses-permission>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
In your activity_name.xml file
<com.google.android.gms.ads.AdView
android:id="@+id/questions_adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/ad_unit_id"
android:background="@android:color/background_dark"
android:minHeight="38px"
android:minWidth="250px" >
</com.google.android.gms.ads.AdView>
In the corresponding file activity_name.java
import com.google.android.gms.ads.AdView
AdView mAdView = (AdView)findViewById(R.id.questions_adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
if(mAdView!=null)
{
mAdView.loadAd(adRequest);
}
Note after installing Google Play Service, please follow these steps:
-
import it into workspace from adt-bundle-linux-x86_64-20140702 / sdk / extras / google / google_play_services / libproject / google-play-services_lib.
-
right click project - properties - android - add - select google-play-service hint from dialog.
-
Clean up the project.
Hopefully this will help resolve the error.
source to share