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

  • Home
  • SEARCH
  • 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 9196129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:47:00+00:00 2026-06-17T21:47:00+00:00

I have an ImageButton I just added in my layout, but when I call

  • 0

I have an ImageButton I just added in my layout, but when I call setContentView on the layout my program is now crashing. Looking at logcat, it seems to give me a NullPointerException when trying to create this ImageButton. ic_menu_send.png is in the appropriate drawable folders. Here’s the xml for the ImageButton:

<ImageButton
    android:id="@+id/imageButton1"
    android:src="@drawable/ic_menu_send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/enterPassword2"
    android:layout_alignRight="@id/enterPassword1"
    android:layout_alignTop="@id/enterPassword2"
    android:background="@style/AppTheme"
    android:contentDescription="@string/submit_button" />

And here is the onCreate for this Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first_time); // causes nullpointerexception
    EditText enterPassword1 = (EditText)findViewById(R.id.enterPassword1);
    enterPassword1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            return onEditAction(v);
        }
    });
    EditText enterPassword2 = (EditText)findViewById(R.id.enterPassword2);
    enterPassword2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            return onEditAction(v);
        }
    });
    /*ImageButton submit1 = (ImageButton)findViewById(R.id.imageButton1);
    submit1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText enterPassword1 = (EditText)findViewById(R.id.enterPassword1);
            onEditAction(enterPassword1);
        }
    });*/

The ImageButton part of the code was only commented out for testing, but the program crashes much earlier. Does anyone have an idea of what may be causing this? Thank you for your assistance.

Edit: Here are the logcat logs:

01-27 15:52:11.264: E/AndroidRuntime(31195): FATAL EXCEPTION: main
01-27 15:52:11.264: E/AndroidRuntime(31195): java.lang.RuntimeException: Unable to start activity ComponentInfo{us.securecow.nearfieldunlock/us.securecow.nearfieldunlock.FirstTimeActivity}: android.view.InflateException: Binary XML file line #50: Error inflating class android.widget.ImageButton
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.os.Looper.loop(Looper.java:137)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at java.lang.reflect.Method.invokeNative(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at java.lang.reflect.Method.invoke(Method.java:511)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at dalvik.system.NativeStart.main(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: android.view.InflateException: Binary XML file line #50: Error inflating class android.widget.ImageButton
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.Activity.setContentView(Activity.java:1881)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at us.securecow.nearfieldunlock.FirstTimeActivity.onCreate(FirstTimeActivity.java:19)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.Activity.performCreate(Activity.java:5104)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-27 15:52:11.264: E/AndroidRuntime(31195):    ... 11 more
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: java.lang.reflect.InvocationTargetException
01-27 15:52:11.264: E/AndroidRuntime(31195):    at java.lang.reflect.Constructor.constructNative(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
01-27 15:52:11.264: E/AndroidRuntime(31195):    ... 24 more
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001}
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.content.res.Resources.loadDrawable(Resources.java:1927)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.view.View.<init>(View.java:3328)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.widget.ImageView.<init>(ImageView.java:114)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.widget.ImageButton.<init>(ImageButton.java:87)
01-27 15:52:11.264: E/AndroidRuntime(31195):    at android.widget.ImageButton.<init>(ImageButton.java:83)
01-27 15:52:11.264: E/AndroidRuntime(31195):    ... 27 more
  • 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-06-17T21:47:01+00:00Added an answer on June 17, 2026 at 9:47 pm

    Stack trace says it all:

    Resource is not a Drawable (color or path):

    According to the Android documentation, the background attribute needs either A drawable or a color.

    Full quote:

    A drawable to use as the background. This can be either a reference to
    a full drawable resource (such as a PNG image, 9-patch, XML state list
    description, etc), or a solid color such as “#ff000000” (black).

    Style doesn’t fit any of those criteria, and so, your app crashes at runtime.

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

Sidebar

Related Questions

I want to make an ad banner. Right now i have an imagebutton that
In this layout I have two Views - the ImageButton at bottom right and
I have an xml layout that compiles fine but when I used the intent
I have an imagebutton with an postbackurl and an onclientclick script. When i added
I have an image and I've included it as an ImageButton (but ImageView would
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button
I have ImageButton with CommandArgument attribute which is having multiple Eval value. When I
I have an ImageButton that I want to fill its parent RelativeLayout container for
I have an ImageButton with an onclientclick js function attached: deleteButton = new ImageButton();
I have an ImageButton in ASP.Net on my site, filled with the property ToolTop:

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.