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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:37:07+00:00 2026-05-23T07:37:07+00:00

I’m following this tutorial to learn Android’s Camera API. I made it the end

  • 0

I’m following this tutorial to learn Android’s Camera API. I made it the end of the first section (right before “Providing an overlay” begins), and I’m getting the following error:

06-20 23:33:50.903: ERROR/AndroidRuntime(1114):     at android.hardware.Camera.startPreview(Native Method)
06-20 23:33:50.903: ERROR/AndroidRuntime(1114):     at com.sobel.Sobel.startCamera(Sobel.java:73)
06-20 23:33:50.903: ERROR/AndroidRuntime(1114):     at com.sobel.Sobel.surfaceChanged(Sobel.java:36)

(Full trace)

Git repo here. Main Activity here. Manifest here.

I checked and re-checked my code and have followed the tutorial to a t, so what could be causing this error?

  • 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-23T07:37:07+00:00Added an answer on May 23, 2026 at 7:37 am

    Try setting the type of Surface in initCamera().

    private void initCamera() {
    mCamSV = (SurfaceView)findViewById(R.id.surface_camera);
    mCamSH = mCamSV.getHolder();
    mCamSH.addCallback(this);
    **mCamSH.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);**
    
    }
    

    EDIT 1

    I am copying all the files here which worked for me with android 2.2 sdk

    Activity

    package com.stack.camera;
    
    
    import java.io.IOException;
    
    import android.app.Activity;
    import android.hardware.Camera;
    import android.os.Bundle;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.WindowManager;
    import android.widget.FrameLayout;
    
    public class CameraStackActivity extends Activity implements SurfaceHolder.Callback {
        private Camera mCam;
        private SurfaceView mCamSV;
        private SurfaceHolder mCamSH;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        initCamera();
    }
    
    @Override
    public void onDestroy() {
        stopCamera();
    }
    
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
    
        startCamera(holder, width, height);
    }
    
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        mCam = Camera.open();
        try {
            mCam.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
    
    }
    
    private void initCamera() {
        mCamSV = (SurfaceView)findViewById(R.id.surface_camera);
        mCamSH = mCamSV.getHolder();
        mCamSH.addCallback(this);
        mCamSH.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
    }
    
    
    private void startCamera(SurfaceHolder sh, int width, int height) {
        Camera.Parameters p = mCam.getParameters();
        // Camera.Size s = p.getSupportedPreviewSizes().get(0);
        p.setPreviewSize(width, height);
    
        mCam.setParameters(p);
    
        try {
            mCam.setPreviewDisplay(sh);
        } catch (Exception e) {
        }
    
        mCam.startPreview();
    }
    
    private void stopCamera() {
        mCamSH.removeCallback(this);
    
        mCam.stopPreview();
        mCam.release();
    }
    

    }

    Layout

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <SurfaceView android:id="@+id/surface_camera"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />
    </FrameLayout>
    

    Manifest File

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.stack.camera"
          android:versionCode="1"
          android:versionName="1.0">
    
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name="CameraStackActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    </manifest>
    

    Check if it still doesnt work out for you.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and

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.