0

我的代码

public class MainActivity extends Activity {

        private View TakePhotoBtn;

        private ImageView ProductPhoto;

        private Button ReviewBtn;

        public static File file;

        private static final int CAMERA_REQUEST = 1888;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
              .....

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }

        void TakePhoto() {

                Intent cameraIntent = new Intent(
                                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                file = new File(Environment.getExternalStorageDirectory()
                                + File.separator + "test.png");
                Uri imageUri = Uri.fromFile(file);

                cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                                imageUri);
                BugTrackerApp.app.file =file ;

                startActivityForResult(cameraIntent, CAMERA_REQUEST);

        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);

                if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {



// this line is getting null value .... why 

                        file =  BugTrackerApp.app.file ;
                        Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
                         ProductPhoto.setImageBitmap(bitmap);
                         ReviewAct.ImageFile = file;

                }
        }

}
4

2 回答 2

1

大概你的进程在你在后台时被终止了。除了缓存之外,不要依赖静态数据成员。

于 2013-11-10T23:32:37.260 回答
0

你做了BugTrackerApp什么?你检查过吗?为什么需要两条线?

BugTrackerApp.app.file =file ;
file =  BugTrackerApp.app.file ;

您创建了一个文件来存储捕获的图像,并将其解码为onActivityResult. 所以这条线

file = new File(Environment.getExternalStorageDirectory()
                                + File.separator + "test.png");

足够的。

于 2013-11-11T02:06:32.527 回答