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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:25:55+00:00 2026-05-28T16:25:55+00:00

I have a custom View extending SurfaceView. The XML layout is <com.myPackage.MyCustomView android:id=@+id/mycview android:layout_width=fill_parent

  • 0

I have a custom View extending SurfaceView. The XML layout is

<com.myPackage.MyCustomView
  android:id="@+id/mycview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>

The class is :

public class MyCustomView extends SurfaceView{

public float[] xpositions;
public float[] ypositions;
public String[] units;


public MyCustomView(Context context, float[] xpos, float[] ypos,String[] u) {
    super(context);
    xpositions=xpos;
    ypositions =ypos;
    units=u;


     }
}

In the context Activity for this method, I have the following line

MyCustomView mv = (MyCustomView)findViewById(R.id.mycview);

The Logcat output has the following

01-30 01:51:12.124: ERROR/AndroidRuntime(4934): Caused by:  java.lang.NoSuchMethodException:MyCustomView(Context,AttributeSet) 
01-30 01:51:12.124: ERROR/AndroidRuntime(4934):    at java.lang.Class.getMatchingConstructor(Class.java:674) 
01-30 01:51:12.124: ERROR/AndroidRuntime(4934):     at java.lang.Class.getConstructor(Class.java:486) 
01-30 01:51:12.124: ERROR/AndroidRuntime(4934):     at android.view.LayoutInflater.createView(LayoutInflater.java:475)

For some reason, my constructor is causing above exception. I would appreciate any help finding what is wrong with the code.

UPDATE:
I changed the constructor to add AttributeSet and in my activity wrote the following:

 XmlPullParser parser = getResources().getXml(R.id.mycview);
 AttributeSet attributes = Xml.asAttributeSet(parser);


 MyCustomView cv = new MyCustomView(this,attributes,xx,yy,uu);
              cv = (MyCustomView)findViewById(R.id.mycview);

But I get the same logcat output.

  • 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-28T16:25:56+00:00Added an answer on May 28, 2026 at 4:25 pm

    You don’t have the correct constructor MyCustomView(Context,AttributeSet)

    You must create the following constructors if you want to inflate views, and create new one in code.
    use initYourStuff() to init your stuff 😉 , you can also parametrize them of course…

    public MyCustomView(Context context)
    {
        super(context);
        this.context = context;
        initYourStuff();
    
    }
    
    public MyCustomView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.context = context;
        initYourStuff();
    }
    
    public MyCustomView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        this.context = context;
        initYourStuff();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom view by extending Relative Layout and it looks like
I have a grid view which is populated using a custom ImageAdapter class extending
I have created a custom view by extending AutoCompleteTextView (with a specialized function called
So I'm extending a custom SurfaceView and am attempting to make it have pinch-zoom
I am making an Android app, and have created a custom view to do
I have a custom view in my layout and I also have a TextView
For Android, I have a custom view which I fill up with primitive shapes
I have the following problem: I want to add a custom view (custom_view.xml and
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have a custom control/view that observes the direction of a gesture within its

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.