Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:10:03+00:00 2026-05-22T22:10:03+00:00

I am new to android development, but I am trying to add admob to

  • 0

I am new to android development, but I am trying to add admob to my app which is using a surfaceview (panelView – GameView).

I tried following http://rx-games.com/admob-adverts-on-surfaceview-no-xml-tutorial/ but I must be doing something wrong, as rl.addView(panelView); adds a nullPointerException. Any help is greatly appreciated.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    //setContentView(R.layout.main);
    AdView adView = new AdView(this, AdSize.BANNER, "a14ded47ad3779e");
    panelView = (GameView) findViewById(R.id.gameScreen);

    RelativeLayout rl = new RelativeLayout(this);
    rl.addView(panelView);
    rl.addView(adView);

    setContentView(rl);

    threadView = panelView.getThread();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:10:04+00:00Added an answer on May 22, 2026 at 10:10 pm

    You are inflating the GameView class from an xml layout and add it to a root View that is not the one defined in that same xml. You have two options:

    1. You create your SurfaceView entirely in Java (as in the example you posted)

    2. You include the AdView in the xml layout (I would prefer this option over the other one)

    If you name the xml file game_layout.xml, you use it as:

    setContentView(R.layout.game_layout.xml);
    

    game_layout.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
      <com.google.ads.AdView 
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="@string/admob_id"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"
        android:layout_alignParentBotom="true"
        />
      <your.package.GameView 
        android:id="@+id/gameScreen"
        android:layout_alignParentTop="true"
        android:layout_above="@id/adView"
      />
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to android development and I've developed a small app but I'm facing
I'm new to Android development, i'm trying to port an IOS app to Android.
I'm new to Android development. I'm trying to get a simple HelloWorld app going
im fairly new to android development, but i'm having some trouble trying to make
I'm new to android development and I'm trying to make an android app that
I am new to Android development. I am trying to use the following code
I am new to android development and I've hit a hurdle when trying to
I am new to Android development and facing a problem while using AndEngine. I
I'm new in android development and I am trying out the WebView example in
I'm very new to Android development and just started to study. What I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.