Google Drive on android error: java.lang.IllegalArgumentException: the name must not be empty: null -
i got stuck "java.lang.illegalargumentexception: name must not empty: null" exception on google drive android app.
i have been googling several day without getting clue. code (an easy example) file list on google drive: (it taken here: google drive sdk exception)
import java.io.ioexception; import java.util.arraylist; import android.accounts.account; import android.accounts.accountmanager; import android.app.activity; import android.app.progressdialog; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import com.google.android.gms.auth.googleauthexception; import com.google.android.gms.auth.googleauthutil; import com.google.android.gms.auth.userrecoverableauthexception; import com.google.android.gms.common.accountpicker; import com.google.api.client.auth.oauth2.bearertoken; import com.google.api.client.auth.oauth2.credential; import com.google.api.client.extensions.android.http.androidhttp; import com.google.api.client.googleapis.extensions.android.accounts.googleaccountmanager; import com.google.api.client.googleapis.extensions.android.gms.auth.googleaccountcredential; import com.google.api.client.http.httprequestfactory; import com.google.api.client.http.httptransport; import com.google.api.client.http.json.jsonhttprequest; import com.google.api.client.http.json.jsonhttprequestinitializer; import com.google.api.client.json.jackson.jacksonfactory; import com.google.api.services.drive.drive; import com.google.api.services.drive.drive.files; import com.google.api.services.drive.driverequest; import com.google.api.services.drive.drivescopes; import com.google.api.services.drive.model.file; import com.google.api.services.drive.model.filelist; import com.maiko.xscanpet.r; import com.maiko.xscanpet.cloud.gdrivehelper; public class fool_5 extends activity { private static final int choose_account=0; private static string accountname; private static int request_token=0; private button btn_drive; private context ctx = this; private activity = this; googleaccountcredential mcredential= null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // set gui layout setcontentview(r.layout.fool_5); // set variables access gui controls btn_drive = (button) findviewbyid(r.id.btn_drive); btn_drive.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { chooseaccount(); } }); } public void chooseaccount() { intent intent = accountpicker.newchooseaccountintent(null, null, new string[]{"com.google"}, false, null, null, null, null); startactivityforresult(intent, choose_account); } // fetch access token asynchronously. void getanduseauthtokeninasynctask(account account) { asynctask<account, string, string> task = new asynctask<account, string, string>() { progressdialog progressdlg; asynctask<account, string, string> me = this; @override protected void onpreexecute() { progressdlg = new progressdialog(ctx, progressdialog.style_spinner); progressdlg.setmax(100); progressdlg.settitle("validating..."); progressdlg.setmessage("verifying login data entered...\n\nthis action time out after 10 seconds."); progressdlg.setcancelable(false); progressdlg.setindeterminate(false); progressdlg.setoncancellistener(new android.content.dialoginterface.oncancellistener() { public void oncancel(dialoginterface d) { progressdlg.dismiss(); me.cancel(true); } }); progressdlg.show(); } @override protected string doinbackground(account... params) { return getaccesstoken(params[0]); } @override protected void onpostexecute(string s) { if (s == null) { // wait intent } else { accountname = s; getdrivefiles(); } progressdlg.dismiss(); } }; task.execute(account); } /** * fetches token particular google account chosen user. not run directly. must run asynchronously inside asynctask. * @param activity * @param account * @return */ private string getaccesstoken(account account) { try { return googleauthutil.gettoken(ctx, account.name, "oauth2:" + drivescopes.drive); // important: drivescopes must changed depending on level of access want } catch (userrecoverableauthexception e) { // start approval screen intent, if not run activity, add intent.flag_activity_new_task flag. a.startactivityforresult(e.getintent(), request_token); e.printstacktrace(); return null; } catch (googleauthexception e) { e.printstacktrace(); return null; } catch (ioexception e) { e.printstacktrace(); return null; } } private drive getdriveservice() { mcredential = googleaccountcredential.usingoauth2(this, drivescopes.drive); mcredential.setselectedaccountname(accountname); return gdrivehelper.getdriveservice(mcredential,getresources().getstring(r.string.app_name)); } /** * obtains list of files on signed-in user's google drive account. */ private void getdrivefiles() { thread t = new thread(new runnable() { @override public void run() { drive service = getdriveservice(); log.d("sitetrack", "function getdrivefiles()"); files.list request; try { request = service.files().list(); // .setq("mimetype=\"text/plain\""); } catch (ioexception e) { e.printstacktrace(); return; } { filelist files; try { system.out.println("got here"); log.d("sitetrack", request.tostring()); //mcredential.setselectedaccountname(accountname); files = request.execute(); } catch (ioexception e) { e.printstacktrace(); log.d("sitetrack", "exception"); return; } arraylist<file> filelist = (arraylist<file>) files.getitems(); log.d("sitetrack", "files found: " + files.getitems().size()); (file f : filelist) { string fileid = f.getid(); string title = f.gettitle(); log.d("sitetrack", "file " + fileid + ": " + title); } request.setpagetoken(files.getnextpagetoken()); } while (request.getpagetoken() != null && request.getpagetoken().length() >= 0); } }); t.start(); } protected void onactivityresult(final int requestcode, final int resultcode, final intent data) { if (requestcode == choose_account && resultcode == result_ok) { accountname = data.getstringextra(accountmanager.key_account_name); googleaccountmanager gam = new googleaccountmanager(this); getanduseauthtokeninasynctask(gam.getaccountbyname(accountname)); log.d("sitetrack", "choose_account"); } else if (requestcode == request_token && resultcode == result_ok) { accountname = data.getstringextra(accountmanager.key_account_name); log.d("sitetrack", "request_token"); } } }
this generates trace on files = request.execute(); or request.execute():
04-20 01:40:26.105: e/androidruntime(27203): fatal exception: thread-39033 04-20 01:40:26.105: e/androidruntime(27203): java.lang.illegalargumentexception: name must not empty: null 04-20 01:40:26.105: e/androidruntime(27203): @ android.os.parcel.readexception(parcel.java:1429) 04-20 01:40:26.105: e/androidruntime(27203): @ android.os.parcel.readexception(parcel.java:1379) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.android.gms.internal.x$a$a.a(unknown source) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.android.gms.auth.googleauthutil.gettoken(unknown source) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.android.gms.auth.googleauthutil.gettoken(unknown source) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.googleapis.extensions.android.gms.auth.googleaccountcredential.gettoken(googleaccountcredential.java:192) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.googleapis.extensions.android.gms.auth.googleaccountcredential$requesthandler.intercept(googleaccountcredential.java:217) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.http.httprequest.execute(httprequest.java:888) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:407) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:340) 04-20 01:40:26.105: e/androidruntime(27203): @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.execute(abstractgoogleclientrequest.java:458) 04-20 01:40:26.105: e/androidruntime(27203): @ com.maiko.fool.fool_5$3.run(fool_5.java:184) 04-20 01:40:26.105: e/androidruntime(27203): @ java.lang.thread.run(thread.java:856)
i feel lost this, without no clue wrong.i have followed tutorial configuring google api services: https://plus.google.com/u/0/114042449736049687152/posts/cd3l8zcjg5z
thank help.
verify var "accountname" passing "mcredential" object. thats reason of errors. greetings.
Comments
Post a Comment