First of all the code snippets below are part of a Google Cloud Project application and are running on my local client which is a Raspberry Pi 1. In order to be able to send data from a sensor connected to the Pi to the cloud an authorization is needed. All needed client secrets are stored in the "client_secrets.json" which is in src/main/resources.
Project Hierarchy
While trying to use the clients secrets to authorize the below code throws a NullPointerException. It is part of the class "CmdLineAuthenticationProvider" (see Project Hierarchy).
InputStreamReader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(this.clientSecretsFile));
This is probably just a path related error but none of my attempts solving it worked (I tried to adjust the path and also copied the client_secrets.json to different locations in the hope that it finds it). The "clientSecretsFile" gets set to "/client_secret.json" in the "RaspiApp" class.
CmdLineAuthenticationProvider provider = new CmdLineAuthenticationProvider();
provider.setClientSecretsFile("client_secret.json");
provider.setScopes(SCOPES);
// get the oauth credentials using the client secrets
Credential credential = provider.authorize();
In my pom.xml I specified the resources as follows:
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
Complete error code:
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at de.econfood.pi.app.CmdLineAuthenticationProvider.getCredential(CmdLineAuthenticationProvider.java:102)
at de.econfood.pi.app.CmdLineAuthenticationProvider.authorize(CmdLineAuthenticationProvider.java:64)
at de.econfood.pi.app.RaspiApp.getSensorEndpoint(RaspiApp.java:171)
at de.econfood.pi.app.RaspiApp.sendSensorData(RaspiApp.java:144)
at de.econfood.pi.app.RaspiApp.onGetRecsets(RaspiApp.java:126)
at de.econfood.pi.app.BrmReadThread.readBuffer(BrmReadThread.java:112)
at de.econfood.pi.app.BrmReadThread.run(BrmReadThread.java:20)
at java.lang.Thread.run(Thread.java:745)