cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
In need of some #MondayMotivation? Read more

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

157 Views
5 Comments
0 Kudos
Highlighted
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 0smiling face with halo1: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:31smiling face with sunglasses
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
Dropboxer

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

[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

Level 3

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

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

Dropboxer

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

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 .)
Level 3

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

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

Dropboxer

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

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.