problem of starting a camera preview in SurfaceView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem of starting a camera preview in SurfaceView

Postby miles2yup » Wed Nov 04, 2009 10:33 am

Guys,

I'm trying to attach a camera preview window in my application. Now it displayed nothing with a black background when running on the ADV, and promoted an error message such as "The application xxxx has stopped unexpectedly please try again" on the HTC G3. Can anybody help me out?

thx in advanced!


Code snippet:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class HelloWorld extends Activity {
  3.  
  4.  
  5.  
  6.         public void onCreate(Bundle savedInstanceState) {
  7.  
  8.                 super.onCreate(savedInstanceState);
  9.  
  10.                 setContentView(R.layout.main);
  11.  
  12.  
  13.  
  14.                 SurfaceView sv = (SurfaceView) findViewById(R.id.SurfaceView01);
  15.  
  16.                 Camera camera = Camera.open();
  17.  
  18.                 Camera.Parameters p = camera.getParameters();
  19.  
  20.                 p.setPreviewSize(sv.getWidth(), sv.getHeight());
  21.  
  22.                 camera.setParameters(p);               
  23.  
  24.                 try {
  25.  
  26.                         camera.setPreviewDisplay(sv.getHolder());
  27.  
  28.                 } catch (IOException e) {
  29.  
  30.                         // TODO Auto-generated catch block
  31.  
  32.                         e.printStackTrace();
  33.  
  34.                 }
  35.  
  36.  
  37.  
  38.         camera.startPreview();
  39.  
  40.         }
  41.  
  42. }
  43.  
  44.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Last edited by miles2yup on Wed Nov 04, 2009 10:36 am, edited 1 time in total.
miles2yup
Freshman
Freshman
 
Posts: 2
Joined: Wed Nov 04, 2009 10:20 am

Top

Postby miles2yup » Wed Nov 04, 2009 10:35 am

p.s.
The error on the G3 is caused by this line:
"camera.startPreview();"

thx again.
miles2yup
Freshman
Freshman
 
Posts: 2
Joined: Wed Nov 04, 2009 10:20 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests