お世話になります。
###前提・実現したいこと
google drive と自作androidアプリの連携を勉強するために、
http://vividcode.hatenablog.com/entry/20130908/1378613811
という記事を参考にし、記事の筆者が書いたコードをGIT HUBから
落としてきて、実行しました。
テキストボックスに文字列を入力し、Saveボタンを押すと、アプリが落ちて、
下記のエラーが発生し、困っています。
google driveへ自作アプリからデータのセーブとロードを成功させるには、
どうしたらよいですか。
###発生している問題・エラーメッセージ
Process:
1 java.lang.IllegalArgumentException: the name must not be empty: null 2 at android.accounts.Account.<init>(Account.java:48) 3 at com.google.android.gms.auth.zze.getToken(Unknown Source) 4 at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 5 at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:269) 6 at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294) 7 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868) 8 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) 9 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) 10 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) 11 at info.vividcode.android.app.googledrivesample.MainActivity$3.run(MainActivity.java:100)
###該当のソースコード
private void saveTextToDrive() { final String inputText = ((EditText)findViewById(R.id.editText)).getText().toString(); Thread t = new Thread(new Runnable() { @Override public void run() { try { // 指定のタイトルのファイルの ID を取得 String fileIdOrNull = null; FileList list = service.files().list().execute();//MainActivity.javaの100行目 ここで落ちました。 for (File f : list.getFiles()) { if (FILE_TITLE.equals(f.getName())) { fileIdOrNull = f.getId(); } } File body = new File(); body.setName(FILE_TITLE);//fileContent.getName()); body.setMimeType("text/plain"); ByteArrayContent content = new ByteArrayContent("text/plain", inputText.getBytes(Charset.forName("UTF-8"))); if (fileIdOrNull == null) { service.files().create(body, content).execute(); showToast("insert!"); } else { service.files().update(fileIdOrNull, body, content).execute(); showToast("update!"); } // TODO 失敗時の処理? } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { showToast("error occur..."); e.printStackTrace(); } } }); t.start(); }
###試したこと
ブレークポイントやLog.vを使って試したところ、
FileList list = service.files().list().execute();
のserviceの中身はnullではありませんでした。
また、google driveに、google_drive_test.txtという空のファイルを置いて
同じ操作を実行したところ、
fileIdOrNull = f.getId();
というところで、同じ、
java.lang.IllegalArgumentException: the name must not be empty: null
というエラーが出ました。
###補足情報(言語/FW/ツール等のバージョンなど)
android studio 2.3.3使用
よろしくお願い申し上げます。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/13 13:03
2017/09/14 01:02
2017/09/14 12:06
2017/09/14 12:38