2016-03-24 122 views
2

當我嘗試保存拍攝的圖像到谷歌驅動器,我得到以下錯誤:非法參數異常

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 Drive嘗試保存圖片時,我遇到了上述問題。

我目前在Nexus 6物理設備上運行棉花糖。

我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; 
    } 

我會在文件清單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

java.lang.IllegalArgumentException: the name must not be empty: null

它所指的「名稱」是帳戶名稱。確保您正在設置GoogleAccountCredential對象。

mAccountCredential.setSelectedAccountName("[email protected]"); 

注意:請將帳戶名稱設置爲完整電子郵件; [email protected],而不只是user123

+0

我嘗試按照您的建議設置帳戶名稱。但是,我不斷收到上面提到的相同的錯誤。 – ap6491

0

原來存在權限問題。儘管我在AndroidManifest.xml文件中設置了GET_ACCOUNTS權限,但我需要在我的應用設置中手動啓用「通訊錄」權限。

這可能是一個設備特定的問題,因爲我在Android Marshmallow 6.0.1的Nexus 6物理設備上運行我的應用程序。

您可能想檢查您的應用程序設置是否安全。