当我尝试将捕获的图像保存到Google云端硬盘中时,出现以下错误:
java.lang.IllegalArgumentException: the name must not be empty: null
at android.accounts.Account.<init>(Account.java:48)
at com.google.android.gms.auth.zzd.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:279)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.amrutpatil.makeanote.GDActions.search(GDActions.java:290)
at com.amrutpatil.makeanote.GDActions.search(GDActions.java:211)
我可以成功登录并在Google云端硬盘中选择一个文件夹,但是,当我尝试保存图片时,我会遇到上述问题。
我目前在Nexus 6物理设备上运行Marshmallow。
我的GDActions.java代码:
private static ArrayList<GF> search(ArrayList<GF> gfs, com.google.api.services.drive.Drive.Files.List qry) throws IOException {
String npTok = null;
if (qry != null) do {
FileList gLst = qry.execute(); //get an error here
if (gLst != null) {
for (File gFl : gLst.getItems()) {
if (gFl.getLabels().getTrashed()) continue;
gfs.add(new GF(gFl.getTitle(), gFl.getId()));
}
npTok = gLst.getNextPageToken();
qry.setPageToken(npTok);
}
} while (npTok != null && npTok.length() > 0);
return gfs;
}
我在上面的FileList gLst = qry.execute()时收到错误。
在此处调用搜索方法时会发生这种情况:
static ArrayList<GF> search(String prId, String titl, String mime) {
ArrayList<GF> gfs = new ArrayList<>();
String qryClause = "'me' in owners and ";
if (prId != null) qryClause += "'" + prId + "' in parents and ";
if (titl != null) qryClause += "title = '" + titl + "' and ";
if (mime != null) qryClause += "mimeType = '" + mime + "' and ";
qryClause = qryClause.substring(0, qryClause.length() - " and ".length());
com.google.api.services.drive.Drive.Files.List qry = null;
try {
qry = mGOOSvc.files().list().setQ(qryClause)
.setFields("items(id, labels/trashed, title), nextPageToken");
gfs = search(gfs, qry);
} catch (GoogleAuthIOException gaiEx) {
try {
gfs = search(gfs, qry); //Invoked here
} catch (Exception g) {
GDUT.le(g);
}
} catch (Exception e) {
GDUT.le(e);
}
return gfs;
}
答案 0 :(得分:0)
java.lang.IllegalArgumentException: the name must not be empty: null
。
&#34;名称&#34;它指的是帐户名称。确保您正在设置GoogleAccountCredential对象。
mAccountCredential.setSelectedAccountName("user123@gmail.com");
注意:将帐户名称设为完整电子邮件; user123@gmail.com
,而非user123
。
答案 1 :(得分:0)
原来有一个权限问题。虽然我在AndroidManifest.xml文件中设置了GET_ACCOUNTS权限,但我需要在我的应用设置中手动启用“联系人”权限。
这可能是设备特定问题,因为我在使用Android Marshmallow 6.0.1的Nexus 6物理设备上运行我的应用。
您可能需要检查应用设置是否安全。