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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:11:18+00:00 2026-06-08T12:11:18+00:00

I have a customized TextView which implements the three View constructors (nb, this is

  • 0

I have a customized TextView which implements the three View constructors (nb, this is my first stab at an android app):

public class DynamicGeometryTextView extends TextView {

    public DynamicGeometryTextView (Context con) { super(con); }

    public DynamicGeometryTextView (Context con, AttributeSet attrs) {
        super(con, attrs);
    }

    public DynamicGeometryTextView (Context con, AttributeSet attrs, int style) {
        super(con, attrs, style); 
    }

This is a non-static inner class, since it needs to access instance data from the outer class. It appears in an .xml layout:

<view class="cogdis.chalkboard.DisplayText$DynamicGeometryTextView"
    android:id="@+id/chalkboard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /> 

Everything compiles and installs fine, but at runtime:

Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class cogdis.chalkboard.DisplayText$DynamicGeometryTextView
    at android.view.LayoutInflater.createView(LayoutInflater.java:596)                                                                         
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)                                                                  
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)                                                                           
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)                                                                            
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)                                                                            
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)                                                                            
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)                                                       
    at android.app.Activity.setContentView(Activity.java:1867)                                                                                 
    at cogdis.chalkboard.DisplayText.onCreate(DisplayText.java:26)                                                                             
    at android.app.Activity.performCreate(Activity.java:5008)                                                                                  
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)                                                             
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)                                                              
    ... 11 more                                                                                                                                
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]                       
    at java.lang.Class.getConstructorOrMethod(Class.java:460)                                                                                  
    at java.lang.Class.getConstructor(Class.java:431)                                                                                          
    at android.view.LayoutInflater.createView(LayoutInflater.java:561)                                                                         
    ... 22 more                                    

To my eye, this implies it can’t find the (Context, AttributeSet) version of the constructor…but it exists. I’ve looked at a few other SO posts, like Android Custom View Constructor, this all point to the same conclusion (to my eye) and read the API Guide on Custom Components repeatedly, but I’ve been stumped with this for more than an hour.

Anyone have any ideas? Is there a way to debug this further?

FOR POSTERITY, ie., anyone new to this like me, non-static inner classes are a no-go if your custom View is referenced in an XML layout, but if you create it programmatically, it can work, eg:

    LayoutInflater lif = getLayoutInflater();
    ViewGroup layout = (ViewGroup)lif.inflate(R.layout.board, null);

    tv = new DynamicGeometryTextView(this);

    layout.addView((View)tv);

In this case, you only need to match the constructors you actually use. Layout parameters (WRAP_CONTENT, etc) can be set in the constructor via setLayoutParams() which is inherited from View.

  • 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-08T12:11:20+00:00Added an answer on June 8, 2026 at 12:11 pm

    There is no way of instantiating a non-static inner class without reference to an instance of the outer class.

    OuterClass.InnerClass innerObject = outerObject.new InnerClass();
    

    So this could be the reason that the layout inflater failed to inflate your class. Make your class static after removing references to the outer class members.

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

Sidebar

Related Questions

I have a customized BaseAdapter for my listView with this code: public View getView(int
I have used a customized list view in which i have added 4 TextView
I have found and customized this JQuery script, which displays different content when different
I have a listview which is customized to display an image and 2 textview.
I have listview having customized some textview and one imageview. When I long click
I have customized the UIAlertView class. It's working perfectly. I don't want the bounce
I have a customized TabView which displays a ListActivity , but everytime I click
I have customized the camera with custom buttons(UIButton) by overlay view. My iPhone application
I have customized uitableViewcell in which each cell show four data which are related
I have customized the button in this way: <Button BorderBrush=Transparent Name=DialButton Click=DialButton_Click > <StackPanel

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.