Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
rekte
8 years agoExplorer | Level 3
Attempt to read from field 'java.util.List com.dropbox.client2.DropboxAPI$Entry.contents' on a null
I have an android application which has been working perfectly until now. Recently, I'm having an error regarding the dropbox download. I've been using this app and the dropbox download for months but I never had this error yet. I tried to solve it but I found nothing similar. Is something wrong with dropbox or I made some mistake?
My question is why dirent = dropboxAPI.metadata("/", 1000, null, true, null);
dirent becomes null?
Thanks very much in advance!
Code
public void downAndLoad() {
AsyncTask<String, Void, Void> asyncTask = new AsyncTask<String, Void, Void>() {
@Override@Override
protected Void doInBackground(String... strings) {
AndroidAuthSession session = null;
try {
session = buildSession();
} catch (DropboxException e) {
e.printStackTrace();
}
dropboxAPI = new DropboxAPI<>(session);
String[] fnames = null;
DropboxAPI.Entry dirent = null;
try {
dirent = dropboxAPI.metadata("/", 1000, null, true, null);
} catch (DropboxException e) {
e.printStackTrace();
}
}
Error:
10-01 00:31:08.963 11769-11961/com.example.brobert.tonda E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4 Process: com.example.brobert.tonda, PID: 11769 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:318) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762) Caused by: java.lang.NullPointerException: Attempt to read from field 'java.util.List com.dropbox.client2.DropboxAPI$Entry.contents' on a null object reference at com.example.brobert.tonda.dldb_lp$1.doInBackground(dldb_lp.java:149) at com.example.brobert.tonda.dldb_lp$1.doInBackground(dldb_lp.java:126) at android.os.AsyncTask$2.call(AsyncTask.java:304) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762)
5 Replies
- Greg-DB8 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/46531209/dropboxapi-metadata-1000-null-true-null-is-null ]
The SDK you're using uses API v1. As announced last year, API v1 has been retired. You can find more information in the blog post here:
https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/
Now that API v1 has been retired, further API calls to it will fail. You should migrate your app to API v2 instead:
https://github.com/dropbox/dropbox-sdk-java
For reference though, it appears your `dirent` is `null` because you initialize it to `null`, and the `metadata` call now fails because API v1 is retired. Your code catches any `DropboxException` from `metadata` only prints the stack trace, allowing your code execution to continue, using the `dirent` which is still `null`, since `metadata` didn't return.
If you need more time to migrate your app to API v2, we can offer an extension for access to API v1. To request that, please open an API ticket with the relevant app key(s):
- rekte8 years agoExplorer | Level 3
Could you tell me if it's possible like in the v1 that the user doesn't need to login in his/her dropbox accoount, s/he can download from MY dropbox in the android application? Because it was possible in v1 and not possible by google drive
Thanks
- Greg-DB8 years ago
Dropbox Community Moderator
Yes, it is possible to connect just to a single Dropbox account in API v2, similar to how you could with API v1.
The API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. However, it is technically possible to connect to just one account. We don't recommend doing so though, for various technical and security reasons.
However if you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your account and app. (Just be careful not to revoke it, e.g. via https://www.dropbox.com/account/security .) - rekte8 years agoExplorer | Level 3
Thanks for your quick answer. I tell you what I did and would like to do and if you have a better idea please let me know:
I have an android application which does the following: When a user presses a button in the app, it creates ssh connection with my raspberry pi which creates some files and uploads them to my dropbox account.
Until stopping v1, my application searched for the latest file that got uploaded to dropbox and downloaded it, but unfortuantely it's not working now. This is the best solution I could come up with.
Do you have a better idea (how to throw back the files on raspberry pi to my app)?
Thanks
- Greg-DB8 years ago
Dropbox Community Moderator
The official Dropbox API v2 Java SDK does offer the ability to upload and download files programmatically, just like in API v1. For example, in the Dropbox API v2 Java SDK, you can use the upload method to upload files:
https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/files/DbxUserFilesRequests.html#upload-java.lang.String-
I can't offer general app development guidance, but if API v2 isn't working as expected for you, please share the code and error/output you're getting, and I'll be happy to help.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!