SurfaceViewクラスを使用してカメラアクティビティクラスを作成しようとしていますが、エラーが発生します。
これは私のエラーログ猫です
08-28 12:21:11.558: E/AndroidRuntime(989): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.cameraapp/com.example.cameraapp.CameraSurfaceView}: java.lang.InstantiationException: com.example.cameraapp.CameraSurfaceView
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.os.Looper.loop(Looper.java:123)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-28 12:21:11.558: E/AndroidRuntime(989): at java.lang.reflect.Method.invokeNative(Native Method)
08-28 12:21:11.558: E/AndroidRuntime(989): at java.lang.reflect.Method.invoke(Method.java:507)
08-28 12:21:11.558: E/AndroidRuntime(989): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-28 12:21:11.558: E/AndroidRuntime(989): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-28 12:21:11.558: E/AndroidRuntime(989): at dalvik.system.NativeStart.main(Native Method)
08-28 12:21:11.558: E/AndroidRuntime(989): Caused by: java.lang.InstantiationException: com.example.cameraapp.CameraSurfaceView
08-28 12:21:11.558: E/AndroidRuntime(989): at java.lang.Class.newInstanceImpl(Native Method)
08-28 12:21:11.558: E/AndroidRuntime(989): at java.lang.Class.newInstance(Class.java:1409)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-28 12:21:11.558: E/AndroidRuntime(989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
08-28 12:21:11.558: E/AndroidRuntime(989): ... 11 more
これは私のCameraSurfaceActivityです:
package com.example.cameraapp;
import java.io.IOException;
import android.content.Context;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.hardware.Camera;
public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder holder;
private Camera camera;
public CameraSurfaceView(Context context)
{
super(context);
//Initiate the Surface Holder properly
this.holder = this.getHolder();
this.holder.addCallback(this);
this.holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder)
{
try
{
//Open the Camera in preview mode
this.camera = Camera.open();
this.camera.setPreviewDisplay(this.holder);
}
catch(IOException ioe)
{
ioe.printStackTrace(System.out);
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(width, height);
camera.setParameters(parameters);
camera.startPreview();
}
public void surfaceDestroyed(SurfaceHolder holder)
{
// Surface will be destroyed when replaced with a new screen
//Always make sure to release the Camera instance
camera.stopPreview();
camera.release();
camera = null;
}
public Camera getCamera()
{
return this.camera;
}
}
マニフェストでは、権限も定義しました、
android:targetSdkVersion="15" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
今、可能な解決策について私を案内してください
ありがとう
シュマイラ