Reputation: 1519
Following this guide on android studio: https://developers.google.com/sheets/api/quickstart/java?authuser=3
Don't know where to put "credentials.json" file. Tryied lots of places: App, Raw, Resources, ..., none works.
This is the line that crashes:
InputStream in = GoogleAPISample.class.getResourceAsStream("/credentials.json");
if (in == null) {
throw new FileNotFoundException("Resource not found: " + "/credentials.json");
}
And this is the error thrown:
java.io.FileNotFoundException: Resource not found: /credentials.json
at com.xxx.yyy.googleapi.GoogleAPISample.getCredentials(GoogleAPISample.java:66)
at com.xxx.yyy.googleapi.GoogleAPISample.doExcec(GoogleAPISample.java:90)
at com.xxx.yyy.ActivityLogin.OnClick_Login(ActivityLogin.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Any suggestions of where to place such file?
These questions did not help me:
Upvotes: 2
Views: 1217
Reputation: 678
Put it in assets foler and create `InputStream' like
InputStream in = context.getAssets().open(CREDENTIALS_FILE_PATH);
Or like Google suggests: create ressources Folder in project folder.
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
InputStream in = MainActivity.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
Upvotes: 1