-3

Please i would like you to help resolve the "NullPointerException" error issued in my android code:

XML file :

<?xml version="1.0" encoding="utf-8"?>
<merge android:id="@id/TableLayout1" android:background="#ff0099cc"          android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads">
<ImageView android:id="@id/imageView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/asset_bg" android:scaleType="fitXY" />
<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TableRow android:layout_gravity="center_horizontal" android:id="@id/tableRow1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="25.0dip" android:layout_marginTop="25.0dip" android:layout_marginRight="25.0dip" android:layout_marginBottom="25.0dip" android:layout_weight="1.0">
        <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0">
            <ImageView android:id="@id/imageViewLogo" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/asset_form" android:scaleType="fitXY" android:layout_weight="1.0" />
            <ImageView android:id="@id/imageViewSymbol" android:layout_width="125.0dip" android:layout_height="125.0dip" android:layout_marginLeft="45.0dip" android:layout_marginTop="85.0dip" android:src="@drawable/asset_small_logo" />
            <ImageView android:id="@id/imageViewPrevious" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="45.0dip" android:layout_marginBottom="45.0dip" android:src="@drawable/asset_previous" android:layout_alignBottom="@id/imageViewLogo" />
            <ImageView android:id="@id/imageViewNext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="55.0dip" android:src="@drawable/asset_next" android:layout_alignTop="@id/imageViewRandom" android:layout_alignParentRight="true" />
            <ScrollView android:id="@id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="10.0dip" android:layout_marginTop="20.0dip" android:layout_marginRight="5.0dip" android:layout_marginBottom="20.0dip" android:fillViewport="true" android:layout_above="@id/imageViewPrevious" android:layout_below="@id/imageViewSymbol" android:layout_alignLeft="@id/imageViewPrevious" android:layout_alignRight="@id/imageViewNext">
                <TextView android:textAppearance="?android:textAppearanceLarge" android:textSize="32.0sp" android:typeface="serif" android:textStyle="bold" android:textColor="@color/black_overlay" android:gravity="center" android:id="@id/textViewFact" android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" />
            </ScrollView>
            <TextView android:textAppearance="?android:textAppearanceMedium" android:textSize="18.0sp" android:textColor="@color/black_overlay" android:id="@id/textViewIndexTotal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Facts # 1 / 1578" android:layout_alignTop="@id/imageViewSymbol" android:layout_alignRight="@id/imageViewNext" />
            <ImageView android:id="@id/imageViewRandom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="135.0dip" android:layout_marginBottom="45.0dip" android:src="@drawable/asset_random" android:layout_alignBottom="@id/imageViewLogo" android:layout_alignParentRight="true" />
            <ImageView android:id="@id/imageViewShare" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="125.0dip" android:layout_marginBottom="45.0dip" android:src="@drawable/asset_share" android:layout_alignBottom="@id/imageViewLogo" />
            <ImageView android:id="@id/imageViewSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="1.0dip" android:layout_marginRight="10.0dip" android:src="@drawable/asset_zoom" android:layout_toLeftOf="@id/textViewIndexTotal" android:layout_alignTop="@id/textViewIndexTotal" />
            <ImageView android:id="@id/imageViewBrowse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10.0dip" android:src="@drawable/asset_browse" android:layout_toLeftOf="@id/imageViewSearch" android:layout_alignTop="@id/imageViewSearch" android:layout_alignParentLeft="false" android:layout_alignParentTop="false" />
            <TextView android:textAppearance="?android:textAppearanceMedium" android:textSize="18.0sp" android:textStyle="italic" android:textColor="@color/gray_overlay" android:id="@id/textViewSearchStr" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5.0dip" android:layout_marginRight="25.0dip" android:layout_below="@id/textViewIndexTotal" android:layout_alignRight="@id/textViewIndexTotal" android:layout_alignParentLeft="false" android:layout_alignParentTop="false" />
            <ImageView android:id="@id/imageViewNoAd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/asset_no_ad" android:layout_alignTop="@id/imageViewPrevious" android:layout_centerHorizontal="true" />
            <ImageView android:id="@id/imageViewCancelSearch" android:layout_width="20.0dip" android:layout_height="20.0dip" android:src="@drawable/asset_cancel" android:layout_alignTop="@id/textViewSearchStr" android:layout_alignRight="@id/textViewIndexTotal" android:layout_alignBottom="@id/textViewSearchStr" android:layout_alignParentRight="false" />
        </RelativeLayout>
    </TableRow>
    <!-- <TableRow android:layout_gravity="bottom" android:id="@id/tableRowAd" android:background="@color/black_overlay"
    android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" />-->
</TableLayout>

<com.amazon.device.ads.AdLayout
    android:id="@+id/ad_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Java code :

setContentView(R.layout.activity_fullscreen);

// For debugging purposes enable logging, but disable for production builds.

AdRegistration.enableLogging(true);

// For debugging purposes flag all ad requests as tests, but set to false for production builds.

AdRegistration.enableTesting(true);

//Error occurs at this level : findViewByID

this.adView = (AdLayout) findViewById(R.id.ad_view);

//

this.adView.setListener(new SampleAdListener());

What i'm trying to do is integrating Amazon ads to my application, the previous version with google ads works smooth. But, the change i've made to integrate Amazon ads show the error above.

Thanks for your help.

Buddy
  • 10,627
  • 5
  • 40
  • 57
MysteryDev
  • 17
  • 7
  • 3
    [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – sam Oct 16 '15 at 22:55
  • 1
    Oh man, that XML layout. – RogueBaneling Oct 16 '15 at 23:11
  • @RogueBaneling: Please, is there any issue in XML file to correct? Thanks. – MysteryDev Oct 17 '15 at 10:48
  • Where's the logcat stacktrace? Where in your activity is the code that causes the NPE? – laalto Oct 17 '15 at 12:19
  • Thank you all guys. i found the issue, i have multiple versions of layout for different screen densities. When i modified the default ,android studio didn't take the care of the rest of layout versions! – MysteryDev Oct 17 '15 at 12:48

1 Answers1

0

I found the solution myself: The issue is that I have multiple versions of layout for different screen densities. When I modified the default, Android Studio didn't take the care of the rest of layout versions!

trincot
  • 263,463
  • 30
  • 215
  • 251
MysteryDev
  • 17
  • 7