2017-02-06 1 views
2

내 앱을 사용하여 캘린더에 새 일정을 추가하려고합니다. 나는 다음과 같은 코드를 사용캘린더에 일정을 추가하는 중 오류가 발생했습니다. 이름은 비워서는 안됩니다.

E/UncaughtException: java.lang.IllegalArgumentException: the name must not be empty: null 
                     at android.accounts.Account.<init>(Account.java:48) 
                     at com.google.android.gms.auth.zze.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:269) 
                     at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294) 
                     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868) 
                     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) 
                     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) 
                     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) 
                     at com.socialcar.booking_fragment.BookingOwnerDetailFragment.createEvent(BookingOwnerDetailFragment.java:456) 
                     at com.socialcar.booking_fragment.BookingOwnerDetailFragment.onClick(BookingOwnerDetailFragment.java:299) 
                     at android.view.View.performClick(View.java:4615) 
                     at android.view.View$PerformClick.run(View.java:18784) 
                     at android.os.Handler.handleCallback(Handler.java:733) 
                     at android.os.Handler.dispatchMessage(Handler.java:95) 
                     at android.os.Looper.loop(Looper.java:136) 
                     at android.app.ActivityThread.main(ActivityThread.java:5061) 
                     at java.lang.reflect.Method.invokeNative(Native Method) 
                     at java.lang.reflect.Method.invoke(Method.java:515) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603) 
                     at dalvik.system.NativeStart.main(Native Method) 

내가 해결책을 찾기 위해 다른 곳에서 확인하고 오류가 뭔가 잘못된 것 같다 :

public void createEvent() { 
     String token = preferences.getString(Config.GOOGLE_TOKEN, ""); 
     m_credential = GoogleAccountCredential.usingOAuth2(this.getContext(), SCOPES); 
     m_credential.setSelectedAccountName(token); 
     HttpTransport transport = AndroidHttp.newCompatibleTransport(); 
     JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); 
     com.google.api.services.calendar.Calendar service = new com.google.api.services.calendar.Calendar.Builder(
       transport, jsonFactory, m_credential) 
       .setApplicationName("R_D_Location Callendar") 
       .build(); 


     Event event = new Event() 
       .setSummary("Event- April 2016") 
       .setLocation("Dhaka") 
       .setDescription("New Event 1"); 

     DateTime startDateTime = new DateTime("2017-02-26T18:10:00+06:00"); 
     EventDateTime start = new EventDateTime() 
       .setDateTime(startDateTime) 
       .setTimeZone("Asia/Dhaka"); 
     event.setStart(start); 

     DateTime endDateTime = new DateTime("2017-02-26T18:40:00+06:00"); 
     EventDateTime end = new EventDateTime() 
       .setDateTime(endDateTime) 
       .setTimeZone("Asia/Dhaka"); 
     event.setEnd(end); 

     String[] recurrence = new String[]{"RRULE:FREQ=DAILY;COUNT=2"}; 
     event.setRecurrence(Arrays.asList(recurrence)); 

     EventAttendee[] attendees = new EventAttendee[]{ 
       new EventAttendee().setEmail("[email protected]"), 
       new EventAttendee().setEmail("[email protected]"), 
     }; 
     event.setAttendees(Arrays.asList(attendees)); 

     EventReminder[] reminderOverrides = new EventReminder[]{ 
       new EventReminder().setMethod("email").setMinutes(24 * 60), 
       new EventReminder().setMethod("popup").setMinutes(10), 
     }; 
     Event.Reminders reminders = new Event.Reminders() 
       .setUseDefault(false) 
       .setOverrides(Arrays.asList(reminderOverrides)); 
     event.setReminders(reminders); 

     String calendarId = "primary"; 
     try { 
      event = service.events().insert(calendarId, event).execute(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     System.out.printf("Event created: %s\n", event.getHtmlLink()); 

    } 

그러나 event = service.events().insert(calendarId, event).execute(); 라인에서 나는 다음과 같은 오류에 geting하고

토큰을 사용하지만 Google을 사용하여 로그인 할 때 얻을 수 있습니다. 그래서 나는 왜 내가이 오류를 가지고 있는지 전혀 모른다.

+0

해결책을 찾았습니까? – Kaushal28

답변

0

코드를 Calendar Android Quickstart과 비교하면 events().insert을 호출하기 전에 자격 증명과 인증이 먼저 처리되었는지 확인하는 것이 좋습니다.

당신은 getResultsFromApi() 내가 당신의 오류가 찾고있는 이름입니다 생각

mCredential.setSelectedAccountName(accountName); 

라인을 포함 chooseAccount() 메소드 호출을하는 안드로이드 빠른 볼 수 있습니다.

private void getResultsFromApi() { 
     if (! isGooglePlayServicesAvailable()) { 
      acquireGooglePlayServices(); 
     } else if (mCredential.getSelectedAccountName() == null) { 
      chooseAccount(); // <-- makes sure that your account name is verified first 
     } else if (! isDeviceOnline()) { 
      mOutputText.setText("No network connection available."); 
     } else { 
      new MakeRequestTask(mCredential).execute(); // <-- after authentication and authorization, you can now make a request to Calendar API 
     } 
    }