我有一个Android应用程序,一直运作到现在为止。最近,我有关于Dropbox下载的错误。我已经使用这个应用程序和Dropbox下载几个月但我从来没有这个错误。我试图解决它,但我发现没有类似的东西。 Dropbox出了什么问题,或者我犯了一些错误?
修改的
我知道空对象引用是什么,我的问题是为什么
dirent = dropboxAPI.metadata(“/”,1000,null,true,null);
dirent变为空?
非常感谢!
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();
}
}
ArrayList<DropboxAPI.Entry> files = new ArrayList<DropboxAPI.Entry>();
ArrayList<String> dir = new ArrayList<String>();
int i = 0;
for (DropboxAPI.Entry ent : dirent.contents) {
files.add(ent);// Add it to the list of thumbs we can choose from
//dir = new ArrayList<String>();
dir.add(files.get(i++).path);
}
fnames = dir.toArray(new String[dir.size()]);
错误:
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)