Java 零线性布局?

Java 零线性布局?,java,android,android-layout,admob,r.java-file,Java,Android,Android Layout,Admob,R.java File,我正在尝试使用LinearLayout在移动设备上实现广告,因为我在谷歌发布的教程中看到了它。然而,我的LinearLayout一直返回null,并且我已经很长时间没有找到解决方案了 以下是我的MainActivity.java: package com.me.mygdxgame; import android.os.Bundle; import android.widget.LinearLayout; //import android.widget.RelativeLayout; //i

我正在尝试使用LinearLayout在移动设备上实现广告,因为我在谷歌发布的教程中看到了它。然而,我的LinearLayout一直返回null,并且我已经很长时间没有找到解决方案了

以下是我的MainActivity.java:

package com.me.mygdxgame;


import android.os.Bundle;
import android.widget.LinearLayout;
//import android.widget.RelativeLayout;

//import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
//import com.google.ads.AdSize;
//import com.google.ads.AdView;
import com.me.mygdxgame.R;

public class MainActivity extends AndroidApplication {

    AdView adView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = true;

        initialize(new MyGame(), cfg);

        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("XXXXConfidential Ad Unit IDXXXX");

        LinearLayout layout = (LinearLayout) findViewById(R.id.normal);
//      layout.addView(adView);
        if (layout ==null){
            System.out.println("layout doesn't work");
        }
        if (layout !=null){
            System.out.println("layout works");
        }
        if (adView == null){
            System.out.println("adView doesn't work");
        }
        if (adView != null){
            System.out.println("adView works");
        }

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice("XXXXConfidential Test Device CodeXXXXXXX")
        .build();

        if (adRequest == null){
            System.out.println("adRequest doesn't work");
        }
        if (adRequest != null){
            System.out.println("adRequest works");
        }

        adView.loadAd(adRequest);
//      setContentView(layout);
    }

    public void onDestroy(){
        if (adView != null) {
            adView.destroy();
          }
          super.onDestroy();
    }
}
System.out.println
s告诉我除了
布局

下面是我的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/normal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
</LinearLayout>

我对XML一点也不熟悉,所以我不知道问题出在哪里。我已经非常仔细地学习了所有教程,但是我的
布局仍然返回null。有什么帮助吗?我已经尝试解决它超过24小时了…

您没有显示#initialize的代码,但我敢打赌,在该方法的某个地方,您再次调用了#setContentView并覆盖了R.layout.main


这就是为什么您找不到R.is.normal,因为它不存在于您用R.layout.main替换的任何内容中。

一切看起来都正常。你试过清理你的项目吗?是的,我已经清理了我的项目好几次了。谢谢你的回答。我已经解决了这个问题。实际上我现在有一个新问题;我的线性布局覆盖了整个屏幕,而游戏,这就是应用程序的全部内容,它覆盖在这个黑屏后面,没有加载。你能在以下网址查看我的最新问题吗?如果你解决了问题,那么你应该为其他用户发布解决方案。
public static final class id {
    public static final int hybrid=0x7f050004;
    public static final int none=0x7f050000;
    public static final int normal=0x7f050001;
    public static final int satellite=0x7f050002;
    public static final int terrain=0x7f050003;
}
public static final class integer {
    public static final int google_play_services_version=0x7f070000;
}
public static final class layout {
    public static final int main=0x7f030000;
}