当我试图从Dropbox下载文件时,我得到空指针异常

时间:2017-02-16 06:13:40

标签: android dropbox

我不知道我是如何得到空指针异常的。我已经将zip文件上传到dropbox。但是当我尝试从dropbox下载它时,它给出了错误。 我使用了以下代码:

public class DownloadZip extends AsyncTask {
private DropboxAPI<AndroidAuthSession> mDBApi;
@Override
protected Object doInBackground(Object[] params) {

    File sdCardDir = new File(Environment.getExternalStorageDirectory() + "/DoDoDo");
    if (!sdCardDir.exists()){
        sdCardDir.mkdir();
    }
    File file=new File(sdCardDir.getPath()+"/DatabaseZip.zip");
    FileOutputStream outputStream = null;

    try {
        outputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

   DropboxAPI.DropboxFileInfo info;
    try {
       info= mDBApi.getFile("/DatabaseZip.zip", null, outputStream, null);//Getting exception here
        //Log.i("DbExampleLog", "The file's rev is: "
         //       + info.getMetadata().rev);
    } catch (DropboxException e) {
        // TODO Auto-generated catch block

        e.printStackTrace();
    }
    return null;
}

}

我从这里调用函数:

private View.OnClickListener clickHandler = new View.OnClickListener() {

    @Override
    public void onClick(View v) { 
    case R.id.importFromDropBtn:
                Log.d("import", "working");

                new DownloadZip().execute();

1 个答案:

答案 0 :(得分:0)

// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);

在行

中使用之前,使用这些行初始化mDBApi对象
 info= mDBApi.getFile("/DatabaseZip.zip", null, outputStream, null);//Getting exception here

用您的凭据替换APP_KEY,APP_SECRET这些字符串

相关问题