我一直在尝试将来自 Google Drive 的读取数据合并到我的 Android 应用程序中。我首先按照示例应用程序的说明(DriveQuickstart - https://developers.google.com/drive/quickstart-android) 并遇到同样的错误。问题是当我调用 fileList.execute(); 在下面的代码中,调试器抱怨 BaseDexClassLoader 抛出了 ClassNotFoundException。如果我捕获此异常并打印消息,它会告诉我参数字符串不应为空。我确保我已按照设置项目的所有说明进行操作,因为我确信这是我的环境有问题。我玩过 Java 构建路径和这个项目的 Android 目标(当前设置为 Android + Google API),但没有任何帮助。任何想法,将不胜感激!
private void downloadFile() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Files.List fileList = service.files().list().setQ("title = 'tester'");
FileList files = fileList.execute(); //This line causes an exception when executed.
ArrayList<File> myFiles = new ArrayList<File>(1);
myFiles.addAll(files.getItems());
File file = myFiles.get(0);
InputStream inStream = downloadFile(service,file);
String docText = convertStreamToString(inStream);
Log.v("TAG", docText);
}
catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
System.out.println(e.toString() );
}
}
});
t.start();
}
这是示例应用程序中遇到相同问题的方法:
private void saveFileToDrive() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
// File's binary content
java.io.File fileContent = new java.io.File(fileUri.getPath());
FileContent mediaContent = new FileContent("image/jpeg", fileContent);
// File's metadata.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("image/jpeg");
File file = service.files().insert(body, mediaContent).execute(); //Same exception encountered
if (file != null) {
showToast("Photo uploaded: " + file.getTitle());
startCameraIntent();
}
} catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
}