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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:06:19+00:00 2026-06-04T15:06:19+00:00

i am trying to referencing a Main.class that extend SurfaceView to XML layout. the

  • 0

i am trying to referencing a Main.class that extend SurfaceView to XML layout.
the XML is like this:

<AbsoluteLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
    <coba.gesture.Main
        android:id="@+id/LayoDalam"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</AbsoluteLayout>

but it comes to error when i running it.
here’s the errors:

05-29 11:57:05.713: ERROR/AndroidRuntime(806): FATAL EXCEPTION: main
05-29 11:57:05.713: ERROR/AndroidRuntime(806): java.lang.RuntimeException: Unable to start activity ComponentInfo{coba.gesture/coba.gesture.CobaGesture}: android.view.InflateException: Binary XML file line #47: Error inflating class coba.gesture.MainBaby
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.os.Looper.loop(Looper.java:123)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread.main(ActivityThread.java:3647)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at java.lang.reflect.Method.invokeNative(Native Method)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at java.lang.reflect.Method.invoke(Method.java:507)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at dalvik.system.NativeStart.main(Native Method)
05-29 11:57:05.713: ERROR/AndroidRuntime(806): Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class coba.gesture.MainBaby
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.createView(LayoutInflater.java:508)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.Activity.setContentView(Activity.java:1657)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at coba.gesture.CobaGesture.onCreate(CobaGesture.java:19)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     ... 11 more
05-29 11:57:05.713: ERROR/AndroidRuntime(806): Caused by: java.lang.NoSuchMethodException: MainBaby(Context,AttributeSet)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at java.lang.Class.getMatchingConstructor(Class.java:643)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at java.lang.Class.getConstructor(Class.java:472)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     at android.view.LayoutInflater.createView(LayoutInflater.java:480)
05-29 11:57:05.713: ERROR/AndroidRuntime(806):     ... 22 more

My prediction is the errors come from MainBaby.java but i don’t know what is wrong.

UPDATE.

Here’s the source of MainBaby.java that u wanted.

public class MainBaby extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = MainBaby.class.getSimpleName();
private ObjBaby obaby;
private ThreadBaby thread;
private static final float TOUCH_TOLERANCE = 4;

static float static_x = 0;
static float static_y = 0;
float mX, mY;
Paint p;
Path mPath;
Canvas mCanvas;
Bitmap mBitmap;
Paint mBitmapPaint;


public MainBaby(Context context){
    super(context);


    // adding the callback (this) to the surface holder to intercept events

    getHolder().addCallback(this);

    obaby = new ObjBaby(BitmapFactory.decodeResource(getResources(), R.drawable.clue_btn), 50, 50);

    // create the game loop thread
    thread = new ThreadBaby(getHolder(), this);

    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    p = new Paint();
     p.setAntiAlias(true);
     p.setDither(true);
     p.setColor(Color.WHITE);
     p.setStyle(Paint.Style.STROKE);
     p.setStrokeJoin(Paint.Join.ROUND);
     p.setStrokeCap(Paint.Cap.ROUND);
     p.setStrokeWidth(12);



    setFocusable(true);

}



@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    thread.setRunning(true);
    thread.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    boolean retry = true;
    while (retry) {
        try {
            thread.join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        retry = false;
    }
}

private void touch_start(float x, float y) {
    mPath.reset();
    mPath.moveTo(x, y);
    mX = x;
    mY = y;
}

private void touch_move(float x, float y) {
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
        mX = x;
        mY = y;
    }
}

private void touch_up() {
    mPath.lineTo(mX, mY);
    // commit the path to our offscreen
    mCanvas.drawPath(mPath, p);

    // kill this so we don't double draw
    mPath.reset();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    static_x = event.getX();
    static_y = event.getY();

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // delegating event handling to the droid
        obaby.handleActionDown((int)event.getX(), (int)event.getY());
        touch_start(static_x, static_y);



        if (event.getY() > getHeight() - 50) {
            thread.setRunning(false);
            ((Activity)getContext()).finish();
        } else {
            //Log.d(TAG, "Coords: x=" + event.getX() + ",y=" + event.getY());
        }
    } if (event.getAction() == MotionEvent.ACTION_MOVE) {
        // the gestures
        if (obaby.isTouched()) {
            // the droid was picked up and is being dragged
            obaby.setX((int)event.getX());
            obaby.setY((int)event.getY());
            touch_move(static_x, static_y);
        }
    } if (event.getAction() == MotionEvent.ACTION_UP) {
        // touch was released
        if (obaby.isTouched()) {
            touch_up();
            obaby.setTouched(false);


        }
    }
    return true;
}

@Override
protected void onDraw(Canvas canvas) {
    // fills the canvas with black
    canvas.drawColor(Color.BLACK);



    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mPath, p);
    obaby.draw(canvas);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    //mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background_number);
    mCanvas = new Canvas(mBitmap);

}
}
  • 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-04T15:06:20+00:00Added an answer on June 4, 2026 at 3:06 pm

    When you extend a view type and create an instance in an XML like this, behind the scenes Android calls MainBaby(Context context, AttributeSet attrs) where the AttributeSet is everything you defined in XML. But you only overrode the MainBaby(Context context), so to fix this error start here:

    public MainBaby(Context context){
        super(context);
        ...
    

    and cover all your bases by trying this:

    public MainBaby(Context context) {
        super(context);
        init();
    }
    
    public MainBaby(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public MainBaby(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    
    private void init() {
        // Original constructor code here
        ...
    

    The new method init() should contain the initialization code from your first constructor.

    Also, I might be missing something from the code not included but are you trying to reference your MainBaby view here?

    <coba.gesture.Main
        android:id="@+id/LayoDalam"
        ...
    

    If so, I think you meant this:

    <coba.gesture.MainBaby
        android:id="@+id/LayoDalam"
        ...
    

    Lastly, AbsoluteLayout are deprecated because they are not readily portable across screens of different densities. This is from the Developer’s Guide:

    3. Do not use AbsoluteLayout

    Unlike the other layouts widgets, AbsoluteLayout enforces the use of fixed positions to lay out its child views, which can easily lead to user interfaces that do not work well on different displays. Because of this, AbsoluteLayout was deprecated in Android 1.5 (API Level 3).

    You should instead use RelativeLayout, which uses relative positioning to lay out its child views. For instance, you can specify that a button widget should appear "to the right of" a text widget.

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

Sidebar

Related Questions

I'm trying to define a self referencing relationship for a workflow step where that
I am trying to learn Self Referencing Forms . I have read that a
I'm trying to carry over player_id and save to the Stakes table referencing that
I'm trying to build an application that is strongly named. It is referencing a
I'm really new in Android Development and, like many others, I'm trying desperately to
I am trying to pull an xml node's value by referencing the value of
I am trying to find a clean way of referencing an array's index using
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to get comfortable with jQuery and I have encountered some sample code that
I was dealing with hibernate, trying to figure out the run-time class behind proxied

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.