Java 碎片状Admob
我使用appcompact创建了一个空项目,并尝试向其中添加AdMob块 fragment_main.xmlJava 碎片状Admob,java,android,android-fragments,admob,Java,Android,Android Fragments,Admob,我使用appcompact创建了一个空项目,并尝试向其中添加AdMob块 fragment_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/lib/com.google.ads"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.testadmobv.MainActivity$PlaceholderFragment" >
<LinearLayout
android:id="@+id/layout_admob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
在“adView=new adView(getActivity())”行中,“error”Unreachable code“您有
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView; // remove this
adView = new AdView(getActivity()); // this is unreachable coz you have return above.
onCreateView
末尾的返回很好这就是答案。。。您将在findViewById之前写入root。就这些
AdView mAdView = (AdView) root.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
谢谢,搞笑发生了,没有看到“回归”(
AdView mAdView = (AdView) root.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);