android - Trying to read cloudstorage.properties. Getting NullPointerException -


i have problem using google cloud storage in app, i'm failing retrieving googlecredential line, giving me nullpointerexception =

googlecredential credential = new googlecredential.builder() 

i'm trying google application default credentials, don´t have google compute engine, prefer using google app engine.

i'm using line of code making method responsable uploading , downloading file =

private static storage getstorage() {         if (storage == null) {             httptransport httptransport = new nethttptransport();             jsonfactory jsonfactory = new jacksonfactory();              list<string> scopes = new arraylist<>();             scopes.add(storagescopes.devstorage_full_control);              try {                 googlecredential credential = new googlecredential.builder()                         .settransport(httptransport)                         .setjsonfactory(jsonfactory)                         .setserviceaccountid(                                 getproperties().getproperty(account_id_property))                         .setserviceaccountprivatekeyfromp12file(                                 new file(getproperties().getproperty(                                         private_key_path_property)))                         .setserviceaccountscopes(scopes).build();                  storage = new storage.builder(httptransport, jsonfactory,                         credential).setapplicationname(                         getproperties().getproperty(application_name_property))                         .build();             } catch (exception e) {                 e.printstacktrace();             }         }         return storage;     } 

to add more question, after debugging noticed line giving me nullpointerexception in method =

private static properties getproperties() throws exception {          if (properties == null) {             properties = new properties();             inputstream stream = cloudstorage.class                     .getresourceasstream("/cloudstorage.properties");             try {                 properties.load(stream);             } catch (ioexception e) {                 throw new runtimeexception(                         "cloudstorage.properties must present in classpath",                         e);             } {                 stream.close();             }         }         return properties;     } 

specifically line of code =

inputstream stream = cloudstorage.class                         .getresourceasstream("/cloudstorage.properties"); 


Comments