0

I am trying to display the camera view using a class extends surfaceview and implements surfaceholder.callback. in my main activity ViewActivity, as shown below, i instantiate an object from the SurfaceHolderActivity and set it as a view using setContentView(myCameraSurfaceHolder);. while running the app on the device, it crashes and logcat gives an error sayin no empty constructor. please help me to find the error.

ViewActivity:

private SurfaceHolderActivity myCameraSurfaceHolder;
    private android.hardware.Camera myCamera;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
        requestWindowFeature( Window.FEATURE_NO_TITLE );
        getWindow().setFormat(PixelFormat.TRANSPARENT);
        getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN );

        myCameraSurfaceHolder = new SurfaceHolderActivity(this);
        setContentView(myCameraSurfaceHolder);
    }

SurfaceHolderActivity:

public SurfaceHolderActivity(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    this.mySurfaceHorder = this.getHolder();
    this.mySurfaceHorder.addCallback(this);
    //this.mySurfaceHorder.setType(mySurfaceHorder.SURFACE_TYPE_PUSH_BUFFERS);
    //this.mySurfaceHorder.setFormat(mySurfaceHorder.setFormat(PixelFormat.TRANSLUCENT));
}

logcat:

04-24 04:34:07.406: E/AndroidRuntime(21420): FATAL EXCEPTION: main
04-24 04:34:07.406: E/AndroidRuntime(21420): java.lang.RuntimeException: Unable to 
instantiate activity    omponentInfo{com.example.augrealtest00/com.example.augrealtest00.SurfaceHolderActivity}: 
java.lang.InstantiationException: can't instantiate class 
 com.example.augrealtest00.SurfaceHolderActivity; no empty constructor
4

4 に答える 4

0

アクティビティを直接インスタンス化することはできません! コンストラクターを使用してアクティビティを構築することはないため、コンストラクターを使用してパラメーターを渡すことはできません。アクティビティの作成方法については、http://developer.android.com/guide/components/activities.html#Creatingにアクセスしてください。

于 2014-04-24T07:09:03.793 に答える