我一直在尝试将Google Drive中的读取数据合并到我的Android应用程序中。我开始遵循示例应用程序(DriveQuickstart - https://developers.google.com/drive/quickstart-android)的说明并遇到相同的错误。问题是,当我调用fileList.execute();在下面的代码中,调试器会抱怨BaseDexClassLoader抛出了ClassNotFoundException异常。如果我捕获这个异常并打印消息,它会告诉我参数字符串不应该为空。我确保我遵循了设定项目的所有方向,因为我确信这是我的环境出了问题。我玩过Java Build Path和这个项目的Android目标(目前设置为Android + Google API),但没有任何帮助。任何想法,将不胜感激!执行驱动器fileList.execute()会导致ClassNotFoundException
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();
}
您是否试过按照视频教程? ClassNotFoundException正在抛出,因为有些罐子丢失了 –
是的,我观看了视频教程,并且我多次重新创建了该项目,只是出现了相同的错误,即使是示例项目也是如此。我认为它在Windows7机器上工作,但我无法避免在这台XP机器上出现这种异常。 – birdman
如果您正在使用模拟器,我还建议您使用真实设备再试一次 –