android google calendar .. application force close

标签 android google-calendar-api

我正在尝试使用 gdata 访问谷歌日历。但应用程序关闭:( 我已将 gdata-client-1.0.jar 添加为外部 jar。

这是我的文件: rr.java 包 caleda.qwe;

import java.net.URL;

import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarFeed;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class rrr extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String res="not proper";
     // Create a CalenderService and authenticate
        CalendarService myService = new CalendarService("calendar");
        try{
        myService.setUserCredentials("sunnycool333", "XXXXX");

        // Send the request and print the response
        URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/owncalendars/full");
        CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
      //  System.out.println("Calendars you own:");
       // System.out.println();
        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
          CalendarEntry entry = resultFeed.getEntries().get(i);
        //  System.out.println("\t" + entry.getTitle().getPlainText());
          res=entry.getTitle().getPlainText();
        }
        }
        catch (Exception e) {
            // TODO: handle exception
            //System.out.println("not working");
            res=e.toString();
        }

        TextView view = (TextView)findViewById(R.id.TextView01);
        view.setText(res);
    }
}

主.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>

应用程序 list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="caleda.qwe"
      android:versionCode="1"
      android:versionName="1.0">
      <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".rrr"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest> 

谁能帮我指出我的错误。

最佳答案

您的 Activity 可能因 Application Not Responding 而失败对话框,因为您正在 UI 线程上进行网络访问。

尝试使用 AsyncTask .

This question有一些关于 AsyncTask 的示例代码和链接。

关于android google calendar .. application force close,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5209690/

相关文章:

java - 如何以编程方式将事件添加到 Outlook 日历或 Google 日历?

javascript - FullCalendar:使用 Google 日历事件的位置属性

android - 如何帮助用户在 Android 设备上订阅外部日历到 Google 日历?

android - 如何从 fragment 验证 recyclerview 适配器 TextInputEditText?

java - 机器人 : How to set Country code manually in emulator

ios - 刷新前检查GDataServiceGoogleCalendar是否有更新?

ruby-on-rails - 本地测试 Google API 客户端监视事件

android - 使用 Android SDK 发布多部分请求

java - 如何将当前位置与地址列表进行比较并得出 5 英里/10 英里/20 英里内的附近地址?

iphone - 相当于iOS中的R