Hello all ! My app will show the current image from the camera and
bellow the binary version of the image black and white, and will write
some different algorithms make the binary image.

I'm having and error when I try to read from the camera:
11-05 02:27:15.357: ERROR/camera(736): not able to link with the
camera

and after that in my app I have the following
11-05 02:27:15.357: ERROR/camera(736): java.lang.NullPointerException
11-05 02:27:15.357: ERROR/camera(736):     at
com.athanazio.android.camerabinaria.Main.onCreate(Main.java:29)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
11-05 02:27:15.357: ERROR/camera(736):     at
android.os.Handler.dispatchMessage(Handler.java:99)
11-05 02:27:15.357: ERROR/camera(736):     at android.os.Looper.loop
(Looper.java:123)
11-05 02:27:15.357: ERROR/camera(736):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
11-05 02:27:15.357: ERROR/camera(736):     at
java.lang.reflect.Method.invokeNative(Native Method)
11-05 02:27:15.357: ERROR/camera(736):     at
java.lang.reflect.Method.invoke(Method.java:521)
11-05 02:27:15.357: ERROR/camera(736):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
11-05 02:27:15.357: ERROR/camera(736):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-05 02:27:15.357: ERROR/camera(736):     at
dalvik.system.NativeStart.main(Native Method)

I noticed this in the LogCat before the problem that I had
11-05 02:27:14.937: ERROR/MediaPlayer(554): Unable to to create media
player
11-05 02:27:14.947: ERROR/CameraService(554): Failed to load
CameraService sounds.
11-05 02:27:14.957: ERROR/MediaPlayer(554): Unable to to create media
player
11-05 02:27:14.977: ERROR/CameraService(554): Failed to load
CameraService sounds.

this is my current code
package com.athanazio.android.camerabinaria;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;

public class Main extends Activity {

        Camera camera;

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

                try {
                        camera = Camera.open();
                        SurfaceView original = (SurfaceView) 
findViewById(R.id.original);
                        camera.setPreviewDisplay(original.getHolder());
                        Parameters cameraParameters = camera.getParameters();
                        cameraParameters.setPreviewFormat(PixelFormat.RGB_888);

                        camera.setPreviewCallback(new PreviewCallback() {
                                SurfaceView changed = (SurfaceView) 
findViewById(R.id.changed);

                                public void onPreviewFrame(byte[] _data, Camera 
_camera) {
                                        Bitmap bitmap = 
BitmapFactory.decodeByteArray(_data, 0,
                                                        _data.length);

                                        Canvas canvas = new Canvas();
                                        canvas.drawBitmap(bitmap, 0, 0, null);
                                        changed.draw(canvas);
                                }
                        });

                        camera.startPreview();

                } catch (Exception e) {
                        showMessage("error", "not able to use the camera");
                        Log.e("camera", "not able to link with the camera", e);
                }

                setContentView(R.layout.main);
        }


        void showMessage(CharSequence title, CharSequence message){
                Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(title);
                builder.setMessage(message);
                builder.show();
        }

        protected void onDestroy() {
                super.onDestroy();
                if (camera != null) {
                        camera.stopPreview();
                        camera.release();
                }
        }
}

any toughts ?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to