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 7041175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:00:26+00:00 2026-05-28T02:00:26+00:00

Do you know why this make my application to close unexpectedly: b2.setOnClickListener(new View.OnClickListener() {

  • 0

Do you know why this make my application to close unexpectedly:

b2.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                     setContentView(R.layout.id_weather);
                     //getting image form url
                    try {
                          ImageView i = (ImageView)findViewById(R.id.weather_icon);
                          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("www.myimageurl.png").getContent());
                          i.setImageBitmap(bitmap); 
                        } catch (MalformedURLException e) {
                          e.printStackTrace();
                        } catch (IOException e) {
                          e.printStackTrace();
                        }
                    Button b4=(Button)findViewById(R.id.button_weather10);
                    b4.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View l) {

                            System.out.println("Yeah");
                    }
                    }); 
            }
            }); 

If I comment out the second setOnClickListener, it works. Its like a setOnClick inside a SetOnClick doesn’t work.

This is my logcat:

Uncaught handler: thread main exiting due to uncaught exception
java.lang.NullPointerException
at com......MyScreen$2.onClick(MyScreen.java:133)

line 133 is my second On click

  • 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-28T02:00:27+00:00Added an answer on May 28, 2026 at 2:00 am

    I think if you are going to call findViewById() from inside the declaration of a clickListener you’d have to use your activity.this explicitly, like so:

    Button b4=(Button)YourActivity.this.findViewById(R.id.button_weather10);
    

    Otherwise I think it is going to try to call a findViewById() method of a OnClickListener class, which doesn’t exist.

    It also seems like you must be trying to call setContentView() more than once. You have

    setContentView(R.layout.id_weather);
    

    inside your click listener for b2. But if you’ve not yet set the content then you’ll have no button to click. And if you have already set the content once then the second one should fail. You’re only allowed to call setContentView() once I think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI May i know how to make the scroll view as mentioned in this
I keep getting this when I close my application. I know it has something
Guys I know this question is silly but just to make sure: Having in
May I know what is the workaround to make this code passed, in Visual
As you know the dash introduces a comment how can I make this valid?
i don't really know what ruby,gems, or ror is, my objective is make this
I know how to make the intellisense work in a .js file using this
In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know
I admit, I'm new at this whole Android stuff. I am trying to make
Know this might be rather basic, but I been trying to figure out how

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.