One month down in 2025: How are your resolutions coming along? Check out how to get back on track 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)
- Greg-DB
Dropbox Staff
[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):
- rekteExplorer | 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-DB
Dropbox Staff
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 .)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 2 hours ago
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 or Facebook.
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!