我可以将图片上传到谷歌存储,现在我正在尝试下载此文件,但我有一个nullPointerException
try {
List<String> scopes = new ArrayList<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
httpTransport = new com.google.api.client.http.javanet.NetHttpTransport();
// agarro la key y la convierto en un file
AssetManager am = mContext.getAssets();
InputStream inputStream = am.open(mContext.getResources().getString(R.string.storage_p12_key_path)); // you
File file = stream2file(inputStream);
// Google Credentianls
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory)
.setServiceAccountId(mContext.getResources().getString(R.string.storage_mail_id))
.setServiceAccountScopes((scopes)).setServiceAccountPrivateKeyFromP12File(file).build();
String URI = null;
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
GenericUrl url = new GenericUrl(URI);
HttpRequest getRequest;
getRequest = requestFactory.buildGetRequest(url);
com.google.api.client.http.HttpResponse response = getRequest.execute();
String content = response.parseAsString();
Log.d("debug", "response is:" + response.getStatusCode());
Log.d("debug", "response content is:" + content);
} catch (IOException e) {
e.printStackTrace();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
在此行getRequest.execute();我得到nullPointer异常
任何帮助将不胜感激
答案 0 :(得分:1)
没有查看堆栈跟踪,我无法确定,但我认为这是因为URI为空。这一点:
String URI = null;
GenericUrl url = new GenericUrl(URI); //url is to a null URI
HttpRequest getRequest = requestFactory.buildGetRequest(url); //getRequest for a null URL
getRequest.execute() // call to a null URI.