使用BOX ANDROID API V2从box.com下载文件时出现Nullpointer异常?

时间:2015-07-30 07:06:36

标签: android integration box boxapiv2

我正在将BOX.COM与我的android应用程序集成。所以我使用BoxAndroidLibraryV2与我的app.I可以上传文件,但下载文件导致错误。下面是我正在使用的代码。

if (object instanceof BoxAndroidFile) {
            // downloadFile((BoxAndroidFile) object);

            try {
                startActivityForResult(FilePickerActivity.getLaunchIntent(
                        BoxDotComAddDocumentActivity.this, currentFolderId,
                        (BoxAndroidOAuthData) getClient().getAuthData(),
                        IBMECMApp.CLIENT_ID, IBMECMApp.CLIENT_SECRET),
                        PICK_FILE_REQUEST);
            } catch (AuthFatalFailureException e) {
            }

        }       


    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent intent) {

        Log.i(TAG, "requestCode " + requestCode + "  resultCode  " + resultCode);

        switch (requestCode) {      
        case PICK_FILE_REQUEST:
            if (resultCode == Activity.RESULT_CANCELED) {
                Toast.makeText(this, "No file chosen", Toast.LENGTH_LONG)
                        .show();
            } else {
                BoxAndroidFile file = intent
                        .getParcelableExtra(FilePickerActivity.EXTRA_BOX_ANDROID_FILE);
                downloadFile(file);
            }
            break;  

}
}

    public void downloadFile(final BoxAndroidFile file) {
        Toast.makeText(BoxDotComAddDocumentActivity.this,
                "Starting download..." + file.getName(), Toast.LENGTH_LONG)
                .show();
        new AsyncTask<BoxAndroidFile, Void, Boolean>() {

            @Override
            protected Boolean doInBackground(BoxAndroidFile... arg0) {
                try {
                    File f = new File(getFilesDir(), file.getName());

                    Log.i(TAG,
                            "File name is " + file.getName() + " getFilesDir "
                                    + getFilesDir() + " file.getId() "
                                    + file.getId() + "f name  " + f.getName());

                    getClient().getFilesManager().downloadFile(file.getId(), f,
                            null, null);
                } catch (Exception e) {
                    Log.e(TAG, "An error occurred when downloading a file.", e);
                    return false;
                }

                return true;
            }

            @Override
            protected void onPostExecute(Boolean result) {
                if (result) {
                    Toast.makeText(BoxDotComAddDocumentActivity.this,
                            "Successfully downloaded " + file.getName() + ".",
                            Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(BoxDotComAddDocumentActivity.this,
                            "An error occurred when downloading.",
                            Toast.LENGTH_LONG).show();
                }
            }

        }.execute(file);
    }

跟随是logcat响应,同时出现错误

07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): An error occurred when downloading a file. 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): java.lang.NullPointerException: Attempt to invoke interface method 'void com.box.boxjavalibv2.filetransfer.IFileTransferListener.onProgress(long)' on a null object reference 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.box.boxjavalibv2.filetransfer.BoxFileDownload.copyOut(BoxFileDownload.java:262) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.box.boxjavalibv2.filetransfer.BoxFileDownload.execute(BoxFileDownload.java:124) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.box.boxjavalibv2.filetransfer.BoxFileDownload.execute(BoxFileDownload.java:153) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.box.boxjavalibv2.resourcemanagers.BoxFilesManagerImpl.downloadFile(BoxFilesManagerImpl.java:151) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.filenet.ecm.activites.BoxDotComAddDocumentActivity$2.doInBackground(BoxDotComAddDocumentActivity.java:200) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at com.filenet.ecm.activites.BoxDotComAddDocumentActivity$2.doInBackground(BoxDotComAddDocumentActivity.java:1) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at android.os.AsyncTask$2.call(AsyncTask.java:288) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 07-30 12:07:05.947: E/BoxDotComAddDocumentActivity(1419): at java.lang.Thread.run(Thread.java:818)

0 个答案:

没有答案