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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:59:55+00:00 2026-06-09T02:59:55+00:00

I have implemented custom Android SurfaceView and meet error when I add callback for

  • 0

I have implemented custom Android SurfaceView and meet error when I add callback for it.

Here is my code for class SurfaceView:

public class AndroidSurface extends SurfaceView {

    public SurfaceHolder holder;

    public AndroidSurface(Context context, AttributeSet attrs) {
        super(context, attrs);

        holder = getHolder();
        holder.addCallback(new SurfaceHolder.Callback() {

            public void surfaceChanged(SurfaceHolder holder, int format,
                    int width, int height) {
                // TODO Auto-generated method stub

            }

            public void surfaceCreated(SurfaceHolder holder) {
                // TODO Auto-generated method stub

            }

            public void surfaceDestroyed(SurfaceHolder holder) {
                // TODO Auto-generated method stub

            }


        });
    }
}

When I add this view to layout.xml, for example :

<com.app.AndroidSurface
        android:id="@+id/surfaceView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/rightBtn"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1" />

I will met error when show in Graphical Layout : failed to instantiate. (at Plugin : com.android.ide.eclipse.adt) and when run this project, I will have exception. When view in LogCat, I see that Java Null Point Exception.

The strange thing is : if I remove holder.addCallback(new SurfaceHolder.Callback() {... no error met.

This looks strange too me, please tell me how to fixed this.

@ Edited : and the problem because when I getHolder, it doesn’t return surface holder, so holder is null, I don’t know why.

Thanks 🙂

  • 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-09T02:59:56+00:00Added an answer on June 9, 2026 at 2:59 am

    You should check your context and make sure you are doing things in the correct order with respect to your lifecycle. Check out this post surfaceView.getHolder not returning SurfaceHolder

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

Sidebar

Related Questions

I have a custom SurfaceView that looks like this: public class GFXSurface extends Activity
n00b here (first Android project). I have been given a custom video codec that
how to clear the surfaceView in android? I have a class like this -
I have seen many examples of creating a custom titlebar: http://zaman91.wordpress.com/2010/03/16/android-how-to-add-custom-title-bar/ Is there a
I have implemented a custom Layout that extends RelativeLayout. It displays lots of different
I have custom Application class in my Android project that is properly described in
I have implemented a custom ActionMapper which obtains the locale from the URI (the
I have implemented a custom view within another activity into a XML layout. The
In my WCF service I have implemented a custom encoder which inherits from System.ServiceModel.Channels.MessageEncoder
I'm using OSMdroid to implement a mapping application. I have implemented a custom MapTileProvider

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.