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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:18:51+00:00 2026-05-20T17:18:51+00:00

i want to create a custom view class. But I get an error by

  • 0

i want to create a custom view class. But I get an error by run the app.

here my class:

package test.start;

import android.util.AttributeSet;
import android.view.*;
import android.graphics.*;
import android.content.Context;

public class control extends View{
    private Paint paint;

    public control(Context context, AttributeSet attrs, int defStyle){
        super(context, attrs, defStyle);
        init();
    }

    public void init(){
        paint = new Paint();
        paint.setTextSize(12);
        paint.setColor(0xFF668800);
        paint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawText("TEEEST", 100, 100, paint);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        this.setMeasuredDimension(150,200);     
    }
}

and the main.XML

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        android:layout_width="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_height="fill_parent" android:orientation="vertical">
        <TextView android:id="@+id/textView1" android:text="@string/text" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
        <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1">
            <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:background="@drawable/custom_button" android:layout_weight="1"></Button>
            <Button android:layout_width="wrap_content"  android:id="@+id/button1" android:layout_height="40dip" android:text="@string/button" android:layout_weight="1"></Button>
            <test.control 
              android:id="@+id/control" 
              android:layout_width="match_parent" 
              android:layout_height="match_parent"> </test.control>
        </TableLayout>
    </LinearLayout>

Error Message:

Unable to start activity
ComponentInfo{de.me.start/test.start.StartActivitiy}:
android.view.InflateException: Binary
XML file line #10: Error inflating
class test.start.control
Blockquote

But i can view the control in the graphical layout.

  • 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-20T17:18:52+00:00Added an answer on May 20, 2026 at 5:18 pm

    Try providing another version of the constructor:

    public control(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom control in C#. But every time I have
If you want to create a custom attribute for MS test (say [Repeat(3)] how
I want to create a custom View which contains two buttons without using xml.
I want to create a custom MSBuild task that changes my .cs files before
In C# if I want to create a Custom Event you do something like
I want to know if i can create a custom google maps application,on which
I want to create extra rules in FXCop. Custom Rules to help ensure specific
I want to build my own custom view which should look like the Crysis-GUI.
I want create a drop shadow around the canvas component in flex. Technically speaking
I want to create a Java application bundle for Mac without using Mac. According

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.