#Attempt to invoke virtual method on a null object reference.

10 messages · Page 1 of 1 (latest)

coarse shale
#

** Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference**

Hey guys I'm going through this issue while I'm tryin to implemente something like a clickable view that takes me to a webView page, for the first one it worked pretty well, but as long as I tryied on the second one then... :

ImageView winIcon;
ImageView winBanner;

winIcon = findViewById(R.id.ptw);  // Referenced to the icon
        winBanner = findViewById(R.id.play_win_banner); // Refereced to the banner
        String winUrlAdress = "https://1155.set.qureka.com"; //Url for the Views
        winIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openCustomTab(winUrlAdress);
            }
        });
        winBanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openCustomTab(winUrlAdress);
            }
        });

private void openCustomTab(String url) {

        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));
    }

and also my xml for the second one:

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="@id/frml"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBaseline_toBottomOf="parent">

            <ImageView
                android:id="@+id/play_win_banner"
                android:layout_width="match_parent"
                android:layout_height="70dp"
                android:src="@drawable/bannerads"
                tools:ignore="SpeakableTextPresentCheck" />

        </RelativeLayout>
fast idolBOT
#

This post has been reserved for your question.

Hey @coarse shale! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

lime pewter
coarse shale
#

no pwt is the one that work, it is an circular image that is placed in the first page and the other is a banner placed in other page the xml part of the pwt is ```xml

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/initial_loading"
app:layout_constraintEnd_toEndOf="parent"
android:paddingRight="10dp"
android:paddingBottom="5dp"

        >

        <ImageView
            android:id="@+id/ptw"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/playcoins"
            app:tint="@color/fontColorLight"
            tools:ignore="SpeakableTextPresentCheck" />

    </RelativeLayout>
#

But the pwt works fine, then i added the other one the play_win_banner and then i got the error

lime pewter
#

Odd

#

Can you confirm winBanner is the one that's null

coarse shale
#

yes

coarse shale
#

@lime pewter can you help?