教程有问题

时间:2012-02-11 15:43:10

标签: android android-camera

我正在尝试本教程:http://www.devx.com/wireless/Article/42482/1954但该行似乎存在问题:

catch (Throwable ){ } 

它吐出错误:

Syntax error on token "Throwable", VariableDeclaratorId expected after this token

代码:

        package com.ARtest;

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

        public class CustomCameraView extends SurfaceView
        {
            Camera camera;
            SurfaceHolder previewHolder;
            SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {
        public void surfaceCreated(SurfaceHolder holder) {
        camera=Camera.open();
        try {
        camera.setPreviewDisplay(previewHolder);
        }
        catch (Throwable ){ }
        }
        public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height)
        {
        Parameters params = camera.getParameters();
        params.setPreviewSize(w, h);
        params.setPictureFormat(PixelFormat.JPEG);
        camera.setParameters(params);
        camera.startPreview();
        }
        public void surfaceDestroyed(SurfaceHolder arg0)
        {
        camera.stopPreview();
        camera.release();
        }
        };
    //constructor
    public CustomCameraView(Context ctx)
    {
        super(ctx);
        previewHolder = this.getHolder();
        previewHolder.setType
        (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        previewHolder.addCallback(surfaceHolderListener);
    }


};

1 个答案:

答案 0 :(得分:2)

Throwable之后应该有一个名称,因为它是一个对象。只需将“Throwable”改为“Throwable e”。 VariableDeclaratorId表示一个对象是未命名的,就像你不会将String实例化为

一样
private String = "this will not work";

对于你的第二个问题,课程不需要;在他们的最后。通常,如果有一个结束括号,你不需要;在它之后。

艰难的修复!您可能将其粘贴到eclipse中,并自动导入graphics.camera。将导入更改为hardware.camera,然后尝试。另外,改变

params.setPreviewSize(w, h); 

params.setPreviewSize(width, height);

还要添加导入

import android.hardware.Camera.Parameters;