Java 尝试在Google Drive中保存图像时出现非法参数异常
当我试图将捕获的图像保存到Google Drive中时,出现以下错误:Java 尝试在Google Drive中保存图像时出现非法参数异常,java,android,google-api,google-drive-api,Java,Android,Google Api,Google Drive Api,当我试图将捕获的图像保存到Google Drive中时,出现以下错误: java.lang.IllegalArgumentException: the name must not be empty: null at android.accounts.Account.<init>(Account.java:48) at com.google.android.gms.a
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)
java.lang.IllegalArgumentException:名称不能为空:null
在android.accounts.Account.(Account.java:48)
访问com.google.android.gms.auth.zzd.getToken(未知来源)
在com.google.android.gms.auth.GoogleAuthUtil.getToken(未知来源)
在com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255)
在com.google.api.client.GoogleAppis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:279)
位于com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)上
在com.amrutpatil.makeanote.GDActions.search(GDActions.java:290)上
在com.amrutpatil.makeanote.GDActions.search(GDActions.java:211)上
我可以成功登录并选择Google Drive上的文件夹,但是,当我尝试保存图像时,我遇到了上述问题
我目前正在Nexus 6物理设备上运行棉花糖
My 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;
}
private static ArrayList search(ArrayList gfs,com.google.api.services.drive.drive.Files.List qry)引发IOException{
字符串npTok=null;
如果(qry!=null)do{
FileList gLst=qry.execute();//在此处获取错误
如果(gLst!=null){
对于(文件gFl:gLst.getItems()){
如果(gFl.getLabels().getRashed())继续;
add(新的GF(gFl.getTitle(),gFl.getId());
}
npTok=gLst.getNextPageToken();
qry.setPageToken(npTok);
}
}while(npTok!=null&&npTok.length()>0);
返回gfs;
}
我在上面的文件列表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;
}
静态数组列表搜索(字符串prId、字符串titl、字符串mime){
ArrayList gfs=新的ArrayList();
字符串qryClause=“‘我’在所有者和”;
如果(prId!=null)qryClause+=“'”+prId+“”,在父级和”;
如果(titl!=null)q循环原因+=“title=”“+titl+””和“;
如果(mime!=null)qrycause+=“mimeType=”“+mime+””和“;
qrycause=qrycause.substring(0,qrycause.length()-“and”.length());
com.google.api.services.drive.drive.Files.List qry=null;
试一试{
qry=mGOOSvc.files().list().setQ(qryClause)
.设置字段(“项目(id、标签/垃圾、标题),下一个GetOken”);
gfs=搜索(gfs,qry);
}捕获(GoogleAuthIOException gaiEx){
试一试{
gfs=search(gfs,qry);//在此处调用
}捕获(例外g){
GDUT.le(g);
}
}捕获(例外e){
GDUT.le(e);
}
返回gfs;
}
java.lang.IllegalArgumentException:名称不能为空:null
它所指的“名称”是帐户名称。确保您正在设置GoogleAccountCredential对象
mAccountCredential.setSelectedAccountName("user123@gmail.com");
注意:将帐户名设置为完整电子邮件<代码>user123@gmail.com,而不仅仅是
user123
发现了权限问题。虽然我在AndroidManifest.xml文件中设置了GET_ACCOUNTS权限,但我需要在我的应用程序设置中手动启用联系人权限
这可能是一个特定于设备的问题,因为我是在带有安卓棉花糖6.0.1的Nexus 6物理设备上运行我的应用程序的
为了安全起见,您可能需要检查应用程序设置。我尝试按照您的建议设置帐户名。然而,我不断得到上面提到的相同错误。