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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:45:51+00:00 2026-05-26T13:45:51+00:00

I have this simple layout: <?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 >

  • 0

I have this simple layout:

<?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" >

            <SurfaceView
                android:id="@+id/surfaceView1"
                android:layout_width="fill_parent"
                android:layout_height="0dp" 
                android:layout_weight = "1" />

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center" >

                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="button1" />
                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="button2" />
            </LinearLayout>
</LinearLayout>

This complies and the application runs perfectly.
I wanted to replace the generic SurfaceView with my own custom SurfaceView:

import android.content.Context;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class PuzzleView extends SurfaceView implements SurfaceHolder.Callback {

    public PuzzleView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub  
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub  
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
    }
}

And use that in the layout xml:

<?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" >

                <PuzzleView
                    android:id="@+id/surfaceView1"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp" 
                    android:layout_weight = "1" />
.
.
.

As soon as the activity is created I get an exception:

public class MyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game);
    }

10-29 19:56:25.921: E/AndroidRuntime(287): java.lang.RuntimeException: Unable to start activity ComponentInfo{ybz.pack1/ybz.pack1.MyActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class PuzzleView

Is this not allowed. I can’t find any examples for doing this.

Edit:
Other then the solution given below, its also required to add all the constructors of SurfaceView to PuzzleView:

public PuzzleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
}

public PuzzleView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}
  • 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-26T13:45:51+00:00Added an answer on May 26, 2026 at 1:45 pm

    In your xml layout you also have to write the package(where you declare your class) like this:

    <com.your.package.here.PuzzleView
                        android:id="@+id/surfaceView1"
                        android:layout_width="fill_parent"
                        android:layout_height="0dp" 
                        android:layout_weight = "1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Android activity layout like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout
This is different than the simple 2 column layout. I need to have this
I have a simple layout like below (which only shows a text TEST): <?xml
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have this simple example I can't seems to get working : MERGE INTO
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
i have this simple type from an external webservice: <xsd:element name=card_number maxOccurs=1 minOccurs=1> <xsd:simpleType>
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class

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.