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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:54+00:00 2026-06-04T07:01:54+00:00

I have a custom view that extends LinearLayout, with these constructors: public class CustomView

  • 0

I have a custom view that extends LinearLayout, with these constructors:

public class CustomView extends LinearLayout {

public CustomView(Context context) {
    this(context, null);
}

public CustomView(Context context, AttributeSet attrs) {
    this(context, attrs, R.attr.customViewStyle);
}

public CustomView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    /* set custom attributes with TypedArray */
}

    /* other methods */
}

In my /res/values/attrs.xml:

<attr name="customViewStyle" format="reference" />

<declare-styleable name="CustomeView">
    <attr name="value" format="integer" />
    <attr name="android:imeOptions" />
    <attr name="android:imeActionId" />
    <attr name="android:imeActionLabel" />
</declare-styleable>

In my /res/values/styles.xml:

<style name="AppTheme" parent="@android:style/Theme.Black">
    <item name="android:windowBackground">@drawable/bg_dark_fiber</item>
    <item name="customViewStyle">@style/CustomViewStyle</item>
</style>

<style name="CustomViewStyle">
    <item name="android:clickable">true</item>
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
</style>

AppTheme is set as the theme for the entire application. The desired result is that my custom view is focusable and clickable by default without my having to add those attributes in my layout files (whereas a regular LinearLayout is not). When I run the app, it crashes with the following stack trace:

05-17 14:58:53.010: E/ActivityThread(26767): Failed to inflate
05-17 14:58:53.010: E/ActivityThread(26767): android.view.InflateException: Binary XML file line #8: Error inflating class com.example.customviews.CustomView
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-17 14:58:53.010: E/ActivityThread(26767):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.Activity.setContentView(Activity.java:1657)
05-17 14:58:53.010: E/ActivityThread(26767):    at com.example.pincode.PinCodeActivity.onCreate(PinCodeActivity.java:26)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.os.Looper.loop(Looper.java:130)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.app.ActivityThread.main(ActivityThread.java:3835)
05-17 14:58:53.010: E/ActivityThread(26767):    at java.lang.reflect.Method.invokeNative(Native Method)
05-17 14:58:53.010: E/ActivityThread(26767):    at java.lang.reflect.Method.invoke(Method.java:507)
05-17 14:58:53.010: E/ActivityThread(26767):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
05-17 14:58:53.010: E/ActivityThread(26767):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-17 14:58:53.010: E/ActivityThread(26767):    at dalvik.system.NativeStart.main(Native Method)
05-17 14:58:53.010: E/ActivityThread(26767): Caused by: java.lang.reflect.InvocationTargetException
05-17 14:58:53.010: E/ActivityThread(26767):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-17 14:58:53.010: E/ActivityThread(26767):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-17 14:58:53.010: E/ActivityThread(26767):    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
05-17 14:58:53.010: E/ActivityThread(26767):    ... 21 more
05-17 14:58:53.010: E/ActivityThread(26767): Caused by: java.lang.NoSuchMethodError: android.widget.LinearLayout.<init>
05-17 14:58:53.010: E/ActivityThread(26767):    at com.example.customviews.CustomView.<init>(CustomView.java:98)
05-17 14:58:53.010: E/ActivityThread(26767):    at com.example.customviews.CustomView.<init>(CustomView.java:94)
05-17 14:58:53.010: E/ActivityThread(26767):    ... 24 more

I can’t understand what’s causing the InflateException in the call to super(context, attrs, defStyle). I also tried super(context, attrs, 0), but that doesn’t help, which is really odd because even LinearLayout uses that, as do most other views whose source code I’ve examined.

  • 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-04T07:01:55+00:00Added an answer on June 4, 2026 at 7:01 am

    I found this answer on the Android Developers Google Group:

    The three-argument version of LinearLayout constructor is only
    available with API 11 and higher — i.e. Android 3.0.

    This dependency has to be satisfied at runtime by the actual Android
    version running on the device.

    I was testing on a handset running Gingerbread (2.3.3). Sure enough, when I ran the program on an emulator with ICS (4.0.3), it worked fine. Still hunting for a workaround so I can use my code on pre-Honeycomb.

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

Sidebar

Related Questions

Currently I have a custom view: public class MyView extends View { public MyView(Context
I have a custom View class that extends Spinner. I'm trying to figure out
I have a custom-made view that extends the View class. I would like 2
friends, i have a custom view class public class Zoom extends View { private
I have a custom view that extends one of the framework classes. Most View
I have a map custom view that inherit from MKOverlayPathView. I need this custom
I have a custom view which extends View. I am adding this to an
Ok, I've read around that a custom view must have a constructor with AttributeSet
I have a custom TabHost that adds tabs like this private void setTab(View view,
I have created a custom view named MyDraw ,this is my MyDraw code, public

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.