Null LinearLayout?

I'm trying to use a LinearLayout for implementing ads on mobile devices, because I saw it used in a tutorial put up by Google. However, my LinearLayout keeps returning null, and I haven't been able to find a solution for a long time.

Here is my


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


public class MainActivity extends AndroidApplication {

    AdView adView;
    public void onCreate(Bundle savedInstanceState) {

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

        initialize(new MyGame(), cfg);

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

        LinearLayout layout = (LinearLayout) findViewById(;
//      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")

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

//      setContentView(layout);

    public void onDestroy(){
        if (adView != null) {

The System.out.printlns are telling me that everything works except for the layout

Here's my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

Here's a snippet from my file, in my package:

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;

I'm not familiar at all with XML, so I don't know what the problem is. I've followed all of the tutorials very closely, yet my layout is still returning null. Any help? I've been trying to solve it for more than 24 hours...


You don't show the code for #initialize but I'm willing to bet that somewhere in that method you are calling #setContentView again and overwriting R.layout.main

That is why you cannot find because it doesn't exist in whatever you have replaced R.layout.main with.

Need Your Help

Rename file name with javascript expression

javascript regex replace split string-concatenation

I'm fairly new to javascript and I need to rename or add to an extension of a css and .png file. The script is embedded within an ETL process. I have a variable "prd" that holds the value of the ...