我有一個類訪問本機相機拍照。照片拍攝完成後,它將保存在一個文件夾中,該照片將顯示在新的活動中。意圖問題Android
問題是,我試圖獲取數據後,我把意圖的照片已被採取,但它總是說,意圖是null.pointer.exception
。以下是我的課程,任何人都請幫助我。
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class CameraTestActivity extends Activity {
Button start;
final int TAKE_PICTURE = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
start = (Button)findViewById(R.id.startButton);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
File file = new File(Environment.getExternalStorageDirectory().toString() + "/testImage/" + "toBeUpload.jpg");
Uri imageUri = Uri.fromFile(file);
Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
cameraIntent.putExtra("path", imageUri.toString());
startActivityForResult(cameraIntent,TAKE_PICTURE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
if(resultCode == RESULT_OK)
{
if(requestCode == TAKE_PICTURE)
{
/*ERRROR OCCUR HERE*/
Bundle extras = intent.getExtras();
}
}
}
}
檢查logcat的,他們給其中線的錯誤並嘗試解決它........檢查目的是空的細節? –
可能重複的[Android ACTION_IMAGE_CAPTURE意圖](http://stackoverflow.com/questions/1910608/android-action-image-capture-intent) –