0

I am having some problem for the following layout. The layout is very simple, just using tablelayout with 3 buttons in a row (view = landscape). However there is a "java.lang.NullPointerException " in the preview screen. I have tested and find that it is arised from the ad part, ie. if I delete the ad part, this java.lang.NullPointerException will disappear.

My questions are:

  1. Does ad does not support landscape? Or how to modify the below code?

  2. I would also adopt a interstitialAd. Does interstitialAd support landscape too?

Coding as follows:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"  
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="*" 
    android:background="@drawable/bgd2" >

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_weight="0.5"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/buttonA"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="2dp"
            android:layout_span="4"
            android:background="@drawable/green_btn"
            android:onClick="buttonA_click"
            android:text="1,2,3"
            android:textSize="20dp" />

            <Button
                android:id="@+id/buttonB"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="2dp"
                android:layout_span="4"
                android:background="@drawable/blue_btn"
                android:onClick="button_Email_click"
                android:text="abc!"
                android:textSize="20dp" />        

        <Button
            android:id="@+id/buttonC"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="2dp"
            android:layout_span="4"
            android:background="@drawable/orange_btn"
            android:onClick="buttonC_click"
            android:padding="2dp"
            android:text="Pictures!"
            android:textSize="20dp" />                                   

    </TableRow>

<com.google.ads.AdView 
      android:id="@+id/adView"                         
      android:layout_width="wrap_content"                         
      android:layout_height="50dp"  
      android:background="@android:color/black"
      android:text="Ads Unavailable"
      android:textStyle="bold|italic"                          
      ads:adUnitId="abc123"                        
      ads:adSize="BANNER"     
      ads:refreshInterval="15000"                                                 
      ads:loadAdOnCreate="true"/>    

</TableLayout>
pearmak
  • 4,979
  • 15
  • 64
  • 122
  • 2
    Can you post a stack trace from logcat? – Karakuri Dec 08 '12 at 06:55
  • the logcat does not report wrong, it can be properly executed. But just the eclipse preview says " NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first. java.lang.NullPointerException Exception details are logged in Window > Show View > Error Log " – pearmak Dec 08 '12 at 07:13
  • did you solve your problem? share here when you find it – kumar_android Dec 08 '12 at 07:53
  • This could be from something in the AdView that the layout editor cannot handle. The layout preview tries to instantiate the views in order to preview them. The same sort of thing happened to me with a custom view that created a Typeface from an asset at runtime -- the layout editor couldn't preview it because those assets aren't available yet. I had to wrap that code in an `if (!isInEditMode()) { /*...*/ }` block. – Karakuri Dec 11 '12 at 17:09

1 Answers1

0

only use

android:screenOrientation="landscape"

Community
  • 1
  • 1
Janmejoy
  • 2,721
  • 1
  • 20
  • 38