我正在尝试将此与我的应用程序集成:Capture Image from Camera and Display in Activity
当我打开活动时,我完全使用了作者所写的内容,我得到了一个空指针异常。这是 logcat 的样子:
11-20 15:03:13.178: D/AndroidRuntime(15052): Shutting down VM
11-20 15:03:13.178: W/dalvikvm(15052): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
11-20 15:03:13.189: E/AndroidRuntime(15052): FATAL EXCEPTION: main
11-20 15:03:13.189: E/AndroidRuntime(15052): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dummies.android.taskreminder/com.dummies.android.taskreminder.activity.UsersThoughts}: java.lang.ClassCastException: android.widget.Button
11-20 15:03:13.189: E/AndroidRuntime(15052): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
11-20 15:03:13.189: E/AndroidRuntime(15052): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
因此,我尝试对其进行一些更改,现在每当我从拍照返回活动时,使用此配置时都会出现空指针异常:
//in oncreate
this.imageView = new ImageView(this);
this.imageView = (ImageView) this.imageView.findViewById(R.id.camera_thought);
//method in class file
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
这是错误的样子:
11-20 14:53:39.118: D/AndroidRuntime(14931): Shutting down VM
11-20 14:53:39.118: W/dalvikvm(14931): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
11-20 14:53:39.128: E/AndroidRuntime(14931): FATAL EXCEPTION: main
11-20 14:53:39.128: E/AndroidRuntime(14931): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/89 (has extras) }} to activity {com.dummies.android.taskreminder/com.dummies.android.taskreminder.activity.UsersThoughts}: java.lang.NullPointerException
11-20 14:53:39.128: E/AndroidRuntime(14931): at android.app.ActivityThread.deliverResults(ActivityThread.java:3734)