Reputation: 13
i followed this tutorial to integrate admob in Android Studio. But now in the MainActivity AdFragment class a few symbols are red (**word* *) (Cannot resolve Symbol) and there is nothing in the error log.
public static class AdFragment extends **Fragment** {
@Override
public **View** onCreateView(**LayoutInflater** inflater, **ViewGroup** container,
Bundle savedInstanceState) {
return inflater.**inflate**(R.layout.fragment_ad, container, false);
}
@Override
public void onActivityCreated(Bundle bundle) {
super.**onActivityCreated**(bundle);
AdView mAdView = (AdView) getView().**findViewById**(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
Also in the activity_main.xml
<fragment android:name="com.appname.MainActivity$PlaceholderFragment"
PlaceholderFragment is red
My import statements:
package com.example.admobexample;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
Upvotes: 0
Views: 889
Reputation: 44118
If you were to use an IDE like AndroidStudio you'd have a neatly underlined classes that need to be imported, in order to be used. Also a handy shortcut to import them quickly.
Basically you are missing multiple import statements for example:
import android.app.Fragment;
You can Google the rest by yourself, if you still don't want to use an IDE.
Also in your xml file you didn't change the obvious com.appname
to your package name. It should be:
android:name="com.example.admobexample.MainActivity$PlaceholderFragment"
Of course make sure your MainActivity
contains a static class called PlaceholderFragment
, for the above to work.
Upvotes: 1