cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attempt to read from field 'java.util.List com.dropbox.client2.DropboxAPI$Entry.contents' on a null

Attempt to read from field 'java.util.List com.dropbox.client2.DropboxAPI$Entry.contents' on a null

rekte
Explorer | Level 3

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 5

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):

 

https://www.dropbox.com/developers/contact

rekte
Explorer | 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 .)

rekte
Explorer | 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-DB
Dropbox Staff
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/DbxUserFilesReq...

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.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    rekte Explorer | Level 3
What do Dropbox user levels mean?