从我的应用程序将事件添加到谷歌日历

发布于 2024-11-25 07:57:30 字数 2247 浏览 2 评论 0原文

我有代码。 eclipse中没有错误。但在模拟器中,我收到“应用程序已意外停止”错误。我做了很多研究,但我无法摆脱这个问题。我希望应用程序做的就是将事件添加到我的谷歌日历中。

代码片段:

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   // Set up the URL and the object that will handle the connection:
   URL postUrl = null;
           try {
                   postUrl = new URL("http://www.google.com/calendar/feeds/[email protected]/private/full");
           } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
           try {
                   myService.setUserCredentials("xyz","xyz123");
           } catch (AuthenticationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   EventEntry myEntry = new EventEntry();

   myEntry.setTitle(new PlainTextConstruct("test event"));
   myEntry.setContent(new PlainTextConstruct("Working!!"));

   Person author = new Person("It's me", null, "[email protected]");
   myEntry.getAuthors().add(author);

   DateTime startTime = DateTime.parseDateTime("2011-07-20T15:00:00-08:00");
   DateTime endTime = DateTime.parseDateTime("2011-07-20T17:00:00-08:00");
   When eventTimes = new When();
   eventTimes.setStartTime(startTime);
   eventTimes.setEndTime(endTime);
   myEntry.addTime(eventTimes);

           try {
                   EventEntry insertedEntry = myService.insert (postUrl, myEntry);
           } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           } catch (ServiceException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   setContentView(R.layout.main);
  }

与代码或清单有关吗?

I have the code. No errors in eclipse. But in the emulator, I'm getting "Application has stopped unexpectedly" error. I have done a lot of research but I'm not able to get rid of this. All I want the app to do is to add events to my google calendar.

The code snippet:

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   // Set up the URL and the object that will handle the connection:
   URL postUrl = null;
           try {
                   postUrl = new URL("http://www.google.com/calendar/feeds/[email protected]/private/full");
           } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
           try {
                   myService.setUserCredentials("xyz","xyz123");
           } catch (AuthenticationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   EventEntry myEntry = new EventEntry();

   myEntry.setTitle(new PlainTextConstruct("test event"));
   myEntry.setContent(new PlainTextConstruct("Working!!"));

   Person author = new Person("It's me", null, "[email protected]");
   myEntry.getAuthors().add(author);

   DateTime startTime = DateTime.parseDateTime("2011-07-20T15:00:00-08:00");
   DateTime endTime = DateTime.parseDateTime("2011-07-20T17:00:00-08:00");
   When eventTimes = new When();
   eventTimes.setStartTime(startTime);
   eventTimes.setEndTime(endTime);
   myEntry.addTime(eventTimes);

           try {
                   EventEntry insertedEntry = myService.insert (postUrl, myEntry);
           } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           } catch (ServiceException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

   setContentView(R.layout.main);
  }

Is it anything to do with the code or the manifest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文