Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 超级(fm); } @凌驾 公共片段getItem(int位置){ //调用getItem来实例化给定页面的片段。 //返回占位符片段(定义为下面的静态内部类)。 返回PlaceholderFragment.newInstance(位置+1); } @凌驾 public int getCount(){ //显示共3页。 返回3; } @凌驾 公共字符序列getPageTitle(int位置){ Locale l=Locale.getDefault(); 开关(位置){ 案例0: 返回getString(R.string.title_section1).toUpperCase(l); 案例1: 返回getString(R.string.title_section2.toUpperCase(l); 案例2: 返回getString(R.string.title_section3).toUpperCase(l); } 返回null; } } /** *包含简单视图的占位符片段。 */ 公共静态类占位符片段扩展了片段{ /** *表示此文件节号的片段参数 *碎片。 */ 私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”; /** *返回给定节的此片段的新实例 *号码。 */ 公共静态占位符片段newInstance(int sectionNumber){ 占位符片段=新占位符片段(); Bundle args=新Bundle(); 参数Putin(参数段号,段号); fragment.setArguments(args); 返回片段; } 公共占位符片段(){ } @凌驾 创建视图上的公共视图(布局、充气机、视图组容器、, Bundle savedInstanceState){ 视图根视图=充气机。充气(R.layout.fragment\u欢迎,容器,false); 返回rootView; } }_Android - Fatal编程技术网

Android 超级(fm); } @凌驾 公共片段getItem(int位置){ //调用getItem来实例化给定页面的片段。 //返回占位符片段(定义为下面的静态内部类)。 返回PlaceholderFragment.newInstance(位置+1); } @凌驾 public int getCount(){ //显示共3页。 返回3; } @凌驾 公共字符序列getPageTitle(int位置){ Locale l=Locale.getDefault(); 开关(位置){ 案例0: 返回getString(R.string.title_section1).toUpperCase(l); 案例1: 返回getString(R.string.title_section2.toUpperCase(l); 案例2: 返回getString(R.string.title_section3).toUpperCase(l); } 返回null; } } /** *包含简单视图的占位符片段。 */ 公共静态类占位符片段扩展了片段{ /** *表示此文件节号的片段参数 *碎片。 */ 私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”; /** *返回给定节的此片段的新实例 *号码。 */ 公共静态占位符片段newInstance(int sectionNumber){ 占位符片段=新占位符片段(); Bundle args=新Bundle(); 参数Putin(参数段号,段号); fragment.setArguments(args); 返回片段; } 公共占位符片段(){ } @凌驾 创建视图上的公共视图(布局、充气机、视图组容器、, Bundle savedInstanceState){ 视图根视图=充气机。充气(R.layout.fragment\u欢迎,容器,false); 返回rootView; } }

Android 超级(fm); } @凌驾 公共片段getItem(int位置){ //调用getItem来实例化给定页面的片段。 //返回占位符片段(定义为下面的静态内部类)。 返回PlaceholderFragment.newInstance(位置+1); } @凌驾 public int getCount(){ //显示共3页。 返回3; } @凌驾 公共字符序列getPageTitle(int位置){ Locale l=Locale.getDefault(); 开关(位置){ 案例0: 返回getString(R.string.title_section1).toUpperCase(l); 案例1: 返回getString(R.string.title_section2.toUpperCase(l); 案例2: 返回getString(R.string.title_section3).toUpperCase(l); } 返回null; } } /** *包含简单视图的占位符片段。 */ 公共静态类占位符片段扩展了片段{ /** *表示此文件节号的片段参数 *碎片。 */ 私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”; /** *返回给定节的此片段的新实例 *号码。 */ 公共静态占位符片段newInstance(int sectionNumber){ 占位符片段=新占位符片段(); Bundle args=新Bundle(); 参数Putin(参数段号,段号); fragment.setArguments(args); 返回片段; } 公共占位符片段(){ } @凌驾 创建视图上的公共视图(布局、充气机、视图组容器、, Bundle savedInstanceState){ 视图根视图=充气机。充气(R.layout.fragment\u欢迎,容器,false); 返回rootView; } },android,Android,} 活动代码: <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:layou

}

活动代码:

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".Welcome$PlaceholderFragment">

    <ViewFlipper
        android:id="@+id/viewflipper"
        android:layout_width="fill_parent"
        android:layout_height="240dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="6dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="vertical" >
            <ImageView
                android:layout_marginTop="15dp"
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/windows_pc" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="vertical" >
            <ImageView
                android:layout_marginTop="15dp"
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ViewFlipper>
    <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>

您的活动布局(
activity\u my.xml
)不包含id为
ad\u视图的
AdView
视图。该视图位于您的片段中,在启动活动时尚未加载该片段

您有两种选择:

  • AdView
    代码传输到片段的回调方法,例如
    onCreateView
  • 将AdView直接添加到活动的布局中,如下所示:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">
    
        <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <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>
    
    
    

有关更多信息,请参阅Android。

我做了,但这不是修复that@yuval发布您的活动布局。在帖子中发布above@yuval因此,您确定此
findViewById(R.id.adView)
返回
null
?发布所有活动代码。发布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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".Welcome$PlaceholderFragment">

    <ViewFlipper
        android:id="@+id/viewflipper"
        android:layout_width="fill_parent"
        android:layout_height="240dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="6dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="vertical" >
            <ImageView
                android:layout_marginTop="15dp"
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/windows_pc" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="vertical" >
            <ImageView
                android:layout_marginTop="15dp"
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ViewFlipper>
    <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>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

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