【问题标题】:android google calendar .. application force closeandroid google calendar .. 应用强制关闭
【发布时间】:2013-12-11 13:03:02
【问题描述】:

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

这是我的文件: rrr.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);
    }
}

main.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>

applicationmanifest.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> 

谁能帮我指出我的错误。

【问题讨论】:

  • 您在 Logcat 中遇到的错误是什么?
  • 为什么不粘贴错误日志?这里面有实际的错误,并且会指向发生某些事情(比如空指针异常?)的地方。

标签: android google-calendar-api


【解决方案1】:

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

尝试使用AsyncTask

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

【讨论】:

  • 03-06 16:27:40.259: 错误/dalvikvm(3252): 无法打开堆栈跟踪文件'/data/anr/traces.txt': 权限被拒绝 03-06 16:30: 04.759:错误/AndroidRuntime(3316):错误:线程附加失败 03-06 16:30:06.910:错误/AndroidRuntime(3329):错误:线程附加失败 03-06 16:30:06.910:错误/AndroidRuntime(3335) :未捕获的处理程序:由于未捕获的异常而退出线程主......等...... 03-06 16:30:06.910: ERROR/AndroidRuntime(3335): ... 14 更多 03-06 16: 30:06.910:错误/dalvikvm(3335):无法打开堆栈跟踪文件'/data/anr/traces.txt':权限被拒绝
【解决方案2】:

非常感谢大家..

如果我们再添加两个文件作为外部 jar 文件,问题就解决了..

这两个文件位于gdata客户端src的“deps”文件夹中。 命名:google-collect-1.0-rc1.jar & jsr305.jar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多