1

这是我收到的日志猫

http://pastebin.com/0qXeHwBq

相机应用程序的代码位于此处 https://github.com/CyanogenMod/android_packages_apps_Camera/tree/ics

一旦我启动相机,它会使整个设备崩溃。由于底部附近有一些 pmem 错误,这可能是内核的一个更深层次的问题,但不确定,所以我想我会在这里发布。

4

2 回答 2

1

它在线失败:

469.11-20 21:15:22.659: E/AndroidRuntime(1259): Caused by: java.lang.NullPointerException
470.11-20 21:15:22.659: E/AndroidRuntime(1259):     at com.android.camera.ui.CameraPicker.initialize(CameraPicker.java:60)

这是if (mCameras[CameraInfo.CAMERA_FACING_FRONT].equals(cameraId)) {

所以我猜你是在没有前置摄像头的手机上运行,​​因为mCameras[CameraInfo.CAMERA_FACING_FRONT]它给出了 null。我建议将其更改为:

if (mCameras.lenght > 1 && mCameras[CameraInfo.CAMERA_FACING_FRONT].equals(cameraId)) {
于 2012-11-21T08:10:50.210 回答
0

我想你应该试试我的代码。它如下

public class PhotoActivity extends Activity {

    /** The Constant PICK_IMAGE. */
    private static final int PICK_IMAGE = 0;

    /** The Constant PICK_IMAGE_FROM_GALLERY. */
    private static final int PICK_IMAGE_FROM_GALLERY = 1;

    /** The btn cancel. */
    private Button btnPhotoCamera,btnPhotoGallery,btnCancel;

    /** The img view. */
    private ImageView imgView;

    /** The u. */
    private Uri u;

    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_options);

        imgView=(ImageView)findViewById(R.id.imgDisplayImage);
        btnPhotoCamera=(Button)findViewById(R.id.btnPhotoCamera);
        btnPhotoGallery=(Button)findViewById(R.id.btnPhotoGallery);
        btnCancel=(Button)findViewById(R.id.btnCancel);

        btnPhotoCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent camera=new Intent();
                camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                camera.putExtra("crop", "true");

                File f=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

                u = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myFile.jpg"));
                camera.putExtra(MediaStore.EXTRA_OUTPUT, u);
                startActivityForResult(camera, PICK_IMAGE);
            }
        });

        btnPhotoGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setType("image/*");
                startActivityForResult(intent, PICK_IMAGE_FROM_GALLERY);
            }
        });

        btnCancel.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent goStartUp=new Intent(PhotoActivity.this, StartUpActivity.class);
                goStartUp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(goStartUp);
                finish();
            }
        });
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (resultCode==RESULT_OK )
        {
            if(requestCode == PICK_IMAGE) {

                InputStream is=null;
                try {
                    is = this.getContentResolver().openInputStream(u);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                Bitmap bmp=BitmapFactory.decodeStream(is);
                imgView.setImageBitmap(bmp);
                Log.i("Inside", "PICK_IMAGE");
            }

            if (requestCode == PICK_IMAGE_FROM_GALLERY) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = { MediaStore.Images.Media.DATA };
                Log.d("data",filePathColumn[0]);
                Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String picturePath = cursor.getString(columnIndex);
                cursor.close();
                imgView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
                Log.i("Inside", "PICK_IMAGE_FROM_GALLERY");
            }
        }
    }
}

XML 文件:-

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f0f0f0" >
    <TextView
        android:id="@+id/lblSelectOptions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/two_options"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ff0000" />
    <Button
        android:id="@+id/btnPhotoCamera"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lblSelectOptions"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/camera" />
    <Button
        android:id="@+id/btnPhotoGallery"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnPhotoCamera"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/gallery" />
    <Button
        android:id="@+id/btnCancel"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnPhotoGallery"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:text="@string/cancel" />
    <TextView
        android:id="@+id/lblDisplayImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnCancel"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/below_this_text_image_will_be_displayed"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000"
        android:textSize="13dp" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/lblDisplayImage"
        android:layout_centerInParent="true"
        android:layout_marginTop="10dp"
        android:gravity="bottom" >
        <!--
             <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        -->
        <ImageView
            android:id="@+id/imgDisplayImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/lblDisplayImage"
            android:layout_centerInParent="true"
            android:contentDescription="@string/area_where_image_is_to_be_displayed" />
        <!-- </ScrollView> -->
    </RelativeLayout>
</RelativeLayout>

还可以根据您的使用修改 Android Manifest 文件:-

<manifest....
  <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
<application....
..........
</application>
</manifest>
于 2012-11-26T08:14:13.797 回答