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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:36:47+00:00 2026-06-14T08:36:47+00:00

I am creating an app which requires a custom layout.But after running my app

  • 0

I am creating an app which requires a custom layout.But after running my app it simple force closes.Can anyone suggest the reason and solution if possible

Thanx in advance

this is my main Activity

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }  
}

this is my custom layout class

public class Odo extends View {
    private Paint p;
    private RectF rect;
    public Odo(Context context) {
        super(context);
        Log.e("odo", "constructor");
        init();
        // TODO Auto-generated constructor stub
    }
    public void init() {
        Log.e("odo", "inside init()");
        rect = new RectF();
        p = new Paint(Paint.ANTI_ALIAS_FLAG);
        p.setColor(Color.GREEN);

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        // TODO Auto-generated method stub
        super.onSizeChanged(w, h, oldw, oldh);
        Log.e("odo", "inside onSizeChange");
        rect.set(0, 0, w, h);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        Log.e("odo", "inside onDraw");
        super.onDraw(canvas);

        canvas.drawRect(rect, p);

    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // TODO Auto-generated method stub
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        Log.e("odo", "inside onMeasure");
    }
}

And this is my XML file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <com.example.odo.Odo
        android:id="@+id/odom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>
  • 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-14T08:36:48+00:00Added an answer on June 14, 2026 at 8:36 am

    I believe you need to provide the default constructors that takes AttributeSet and/or int for style reference. For example:

    public class Odo extends View {
        private Paint p;
        private RectF rect;
    
        public Odo(Context context) {
            super(context);
            Log.e("odo", "constructor");
            init();
            // TODO Auto-generated constructor stub
        }
    
        public Odo (Context context, AttributeSet attrs) {
            super(context, attrs);
            Log.e("odo", "constructor");
            init();
        }
    
        public Odo (Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            Log.e("odo", "constructor");
            init();
        }
    
        public void init() {
            Log.e("odo", "inside init()");
            rect = new RectF();
            p = new Paint(Paint.ANTI_ALIAS_FLAG);
            p.setColor(Color.GREEN);
    
        }
    
    //.....  and so on
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of creating an app which requires irregular shaped buttons.
Right now I'm creating a web-app which requires that multiple sets of data (including
I have an app with a manifest that requires running as administrator, but part
I am creating an app which requires the users to enter certain values when
I am creating an app which requires internet. I want to use reachability class
I'm creating an app in CakePHP which requires me to run 'multiple' apps within
Hi i am creating a windows phone 7.1 application, which requires in app purchases
i am creating an iphone app, can someone suggest some framework to handle api
I'm creating an app which requires the footer to remain constant among various activities.
I'm creating an android app that requires database connectivity, for which I'm using the

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.