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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:56:42+00:00 2026-05-27T09:56:42+00:00

findViewById is returning null for me on an ImageView widget. There is no error

  • 0

findViewById is returning null for me on an ImageView widget. There is no error and nothing in logcat that indicates what is going on. The id’s match and other image views are being set properly. Java and xml are linked by the class tag in xml pointing to the class defined in java which is a descendant of RelativeLayout.

I tried changing the name of R.id.more_icon1 and that didn’t work. Tried cleaning and that didn’t work. Used debugger to see that it really does just move on past and when it returns mMoreIcon == null.

What’s wierd is that the other ImageView’s work just fine.

Anyone seen this before or have any ideas?

Java Code: Class is a descendant of RelativeLayout

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mText1 = (TextView) findViewById(R.id.text1);
    mText2 = (TextView) findViewById(R.id.text2);
    mIcon1 = (ImageView) findViewById(R.id.icon1);
    mIcon2 = (ImageView) findViewById(R.id.icon2);
    // mMoreIcon is the one that gets set as null. mIcon1 and mIcon2 work just fine.
    mMoreIcon = (ImageView) findViewById(R.id.more_icon1);

}

XML Code:

<ImageView android:id="@+id/icon1"
    style="@style/SuggestionIcon1"
    android:scaleType="centerInside"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
/>

<!--     This is the icon that is being returned as null -->
<ImageView android:id="@+id/more_icon1"
    style="@style/MoreIcon2"
    android:scaleType="centerInside"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:visibility="gone" />

<ImageView android:id="@+id/icon2"
    style="@style/SuggestionIcon2"
    android:scaleType="centerInside"
    android:layout_toLeftOf="@id/more_icon1"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:visibility="gone" />

Thanks

  • 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-27T09:56:43+00:00Added an answer on May 27, 2026 at 9:56 am

    I had a similar issue and my problem was that findviewbyid only find child views. If the view is a sibling you’d have to call it from the parent. The activity should be able to find it.

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

Sidebar

Related Questions

I have a listview which includes 2 textviews and 1 imageview. Now, the image
ImageView Iv2 = (ImageView)findViewById(R.id.imageView2); textId++; String imgId = full_ + textId; int Ivid =
How to get that working: if(findViewById(ResIdWithUnkownType) instanceof Bitmap) { Bitmap bitmap = (Bitmap) findViewById(ResIdWithUnkownType);
findViewById returns null for EditText Java Code: public class MainActivity extends Activity { private
ImageView connect = (ImageView) findViewById(R.id.fconnect); connect.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { facebook.authorize(SignIn.this,
I consistantly get an error when I run this line moreContent.addView(findViewById(moreViews[0]), 0); extra code:
Welcome to another findviewbyid() returns null question! I wrote an adapter class for displaying
I have an android app that has various activities. for example there is a
I do not know why findViewById(R.id.tv01) is not defined. I mean there is an
Eclipse is marking findViewById(int) as undefined; it was doing the same thing for getResources(),

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.