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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:40:02+00:00 2026-06-07T08:40:02+00:00

I created a Custom View class that takes a path, then fills it white

  • 0

I created a Custom View class that takes a path, then fills it white and colors its edge red:

StrokeFill.java:

package com.kf.pathshape;
...

public class StrokeFill extends View{
private Path shapePath;

public StrokeFill(Context context, Path path) {
    super(context);
    this.shapePath = path;

    // TODO Auto-generated constructor stub
}

public StrokeFill(Context context, AttributeSet attrs, Path shapePath) {
    super(context, attrs);
    this.shapePath = shapePath;
}

protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    //canvas.drawColor(Color.BLACK);
    super.onDraw(canvas);

    //Sets paints and draws the shapes
    Paint fillPaint = new Paint();
    fillPaint.setColor(android.graphics.Color.WHITE);
    fillPaint.setStyle(Paint.Style.FILL);
    fillPaint.setStrokeWidth(0);
    Paint strokePaint = new Paint();
    strokePaint.setColor(android.graphics.Color.RED);
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setStrokeWidth(2);

    canvas.drawPath(shapePath, fillPaint);
    canvas.drawPath(shapePath, strokePaint);
}
}

My layout XML (main.xml) is very simple:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.kf.pathshape.StrokeFill
    android:id="@+id/pathshape"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

Activity:

setContentView(R.layout.main);
shapeView = (StrokeFill) findViewById(R.id.pathshape);
shapeView = new StrokeFill(this, testpath);

testpath is a valid path. It’s giving me errors even if I comment out the lines defining “shapeView”. Logcat:

07-11 01:50:17.150: E/AndroidRuntime(24321): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kf.pathshape/com.kf.pathshape.PathshapeActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.kf.pathshape.StrokeFill
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.os.Looper.loop(Looper.java:130)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread.main(ActivityThread.java:3691)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at java.lang.reflect.Method.invokeNative(Native Method)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at java.lang.reflect.Method.invoke(Method.java:507)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at dalvik.system.NativeStart.main(Native Method)
07-11 01:50:17.150: E/AndroidRuntime(24321): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.kf.pathshape.StrokeFill
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.createView(LayoutInflater.java:508)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:234)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.Activity.setContentView(Activity.java:1679)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at com.kf.pathshape.PathshapeActivity.onCreate(PathshapeActivity.java:73)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
07-11 01:50:17.150: E/AndroidRuntime(24321):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-11 01:50:17.150: E/AndroidRuntime(24321):    ... 11 more
07-11 01:50:17.150: E/AndroidRuntime(24321): Caused by: java.lang.NoSuchMethodException: StrokeFill(Context,AttributeSet)

I searched through the forum but didn’t find what I need. I already defined the constructor taking context and attrs. What am I missing here?

  • 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-07T08:40:04+00:00Added an answer on June 7, 2026 at 8:40 am

    As you are extending a view, you need to implements 3 constructors:

    public class StrokeFill extends View{
        private Path mShapePath;
    
        public StrokeFill(Context context) {
            super(context);
            init();
        }
    
        public StrokeFill(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public StrokeFill(Context context, AttributeSet attrs, int defstyle) {
            super(context, attrs, defstyle);
            init();
        }
    
        private void init(){
            //some code... or not =)
        }
    
        public void setPath(Path path){
            mShapePath = path;
        }
        /* rest of your code */
    }
    

    Then in your activity:

    shapeView = (StrokeFill) findViewById(R.id.pathshape);
    shapeView.setPath(yourPath);
    

    Hope this helps you

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

Sidebar

Related Questions

I've created a UIViewController which contains a view with a custom class that I've
I've created a custom view that loads its content from a nib, like this:
I've created a custom view class and right now just want to draw an
I created a custom view that uses Json.Simple to serialize the model and write
I created a CUSTOM split view (extends a UISplitviewController) in our application so that
So I've created a view controller that creates a custom view that, if it
I created a custom view class because I wanted to have a status item
I created a custom LocationGenerator class that uses CoreLocation and Reverse Geocoding, and generates
Here is the situation: I have created a custom view class with UITextView as
Background: Inspired from Apple's sample code ScrollViewSuite, I've created a view controller class that

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.