Android ACTION_IMAGE_CAPTURE发送结果运行时异常失败

时间:2011-11-12 13:00:32

标签: android runtime-error android-activity

我正在尝试拍照并在我的应用程序中获取图像路径。我使用ACTION_IMAGE_CAPTURE拍照,我成功获取图像路径,但我也得到运行时异常。这是我的代码:

启动相机意图:

public void openDeviceCam() {

    // Setting parameters to camera intent
    String fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, fileName);
    mCapturedImageURI = getContentResolver().insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

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

    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

}

从相机活动中获取结果:

// Returns after photo taken by phone
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

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

        DataHandler handler = DataHandler.getInstance();
        // Photo taken
        imageCount++;
        handleUICompanents();

        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(mCapturedImageURI, projection, null,
                null, null);
        int column_index_data = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String capturedImageFilePath = cursor.getString(column_index_data);
        // Getting path datas to memory
        Log.v("captured image path", capturedImageFilePath);
        handler.setImagePathsToList(capturedImageFilePath);
        ConnectionHandler connectionHandler = new ConnectionHandler();

        // Calculate passed time during post
        long startSec = System.currentTimeMillis();

        // Reques 2
        StringBuilder strBuild = new StringBuilder();
        strBuild.append(UrlConstants.swfUrl)
                .append(UrlConstants.swfUrlParamsUploadType)
                .append("image_").append(handler.getSite()).append("_")
                .append(handler.getDomain());
        String respDataToImage = connectionHandler.postImageAsData(
                strBuild.toString(), handler.getImagePath());

        handler.setUpSwfUploadResponseParams(respDataToImage);

        long finishSec = System.currentTimeMillis();

        // Request 3
        strBuild = new StringBuilder();
        strBuild.append(UrlConstants.savePhotoUrl)
                .append(UrlConstants.savePhotoUrlParamsSt)
                .append(handler.getSt()).append("&")
                .append(UrlConstants.savePhotoUrlParamsAlbum)
                .append(handler.getPath()).append("&")
                .append(UrlConstants.savePhotoUrlParamsUploadedPhotoHash)
                .append(handler.getUploadKey()).append("&")
                .append(UrlConstants.savePhotoUrlParamsCdnDomain)
                .append(UrlConstants.cdnDomain).append("&")
                .append(UrlConstants.savePhotoUrlParamsAppId)
                .append(handler.getSite()).append("&")
                .append(UrlConstants.savePhotoUrlParamsNetmeraDomain)
                .append(handler.getDomain()).append("&")
                .append(UrlConstants.savePhotoUrlParamsViewerId)
                .append(handler.getOpensocialViewerId()).append("&");

        connectionHandler.getData(strBuild.toString(), null);

        Log.v("passed time", String.valueOf(finishSec - startSec));
        Log.v("upload path", handler.getPath());

        // Delete temp image path
        // deleteTempImages();

    }
}

这是我的logcat错误输出:

11-12 14:43:10.469: ERROR/AndroidRuntime(20850): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=-1, data=null} to activity {com.inomera.ttmobilerehber/com.inomera.ttmobilerehber.TTMobileRehberActivity}: java.lang.NullPointerException: println needs a message
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.os.Looper.loop(Looper.java:123)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread.main(ActivityThread.java:3687)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at java.lang.reflect.Method.invokeNative(Native Method)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at java.lang.reflect.Method.invoke(Method.java:507)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at dalvik.system.NativeStart.main(Native Method)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850): Caused by: java.lang.NullPointerException: println needs a message
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.util.Log.println_native(Native Method)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.util.Log.v(Log.java:116)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at com.inomera.ttmobilerehber.TTMobileRehberActivity.onActivityResult(TTMobileRehberActivity.java:155)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
11-12 14:43:10.469: ERROR/AndroidRuntime(20850):     ... 11 more
11-12 14:43:10.489: ERROR/(162): Dumpstate > /data/log/dumpstate_app_error

1 个答案:

答案 0 :(得分:0)

NullPointerException的一次通话中,您TTMobileRehberActivity的第155行有一个Log.v()。不幸的是,你拒绝指出这是哪一行。

既然你说:

  

我成功获取图像路径

然后我必须假设失败的电话不是:

Log.v("captured image path", capturedImageFilePath);

可能失败的唯一其他Log.v()调用是:

Log.v("upload path", handler.getPath());

这指的是一些DataHandler类,大概是你自己创造的。