2011-03-06 6 views
1

J'essaie d'accéder au calendrier google en utilisant gdata. mais l'application ferme :( J'ai ajouté gdata-client-1.0.jar comme pot externeandroid google calendar .. application force fermer

voici mes fichiers: rrr.java package 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> 

Quelqu'un peut-il m'aider s'il vous plaît en soulignant mon erreur.

+0

Quelle est l'erreur que vous obtenez dans Logcat? –

+0

Pourquoi n'avez-vous pas collé le journal des erreurs? Cela a l'erreur réelle à l'intérieur, et pointera vers l'endroit où quelque chose (comme une nullpointerexception?) Se produit. – Nanne

Répondre

1

Votre activité peut être un échec avec la boîte de dialogue Application Not Responding parce que vous faites un accès au réseau sur le thread d'interface utilisateur.

Essayez d'utiliser un AsyncTask.

This question a quelques exemples de code et des liens concernant AsyncTask.

+0

6/3 16: 27: 40,259: ERREUR/dalvikvm (3252): impossible d'ouvrir le fichier de trace pile 'de /data/anr/traces.txt': Autorisation refusée 6/3 16: 30: 04,759: ERREUR/AndroidRuntime (3316): eRREUR: fil attach a échoué 03-06 16: 30: 06,910: eRREUR/AndroidRuntime (3329): eRREUR: fil attach a échoué 03-06 16: 30: 06,910: eRREUR/AndroidRuntime (3335): gestionnaire Uncaught: thread principal sortant en raison de l'exception non interceptée ....... etc ..... 03-06 16: 30: 06.910: ERROR/AndroidRuntime (3335): ... 14 plus 03-06 16:30: 06.910: ERROR/dalvikvm (3335): Impossible d'ouvrir le fichier de trace de la pile '/data/anr/traces.txt': Autorisation refusée –

0

Merci a tout le monde beaucoup ..

Si l'on ajoute deux autres fichiers sous forme de fichiers jar externe, le problème se résout ..

Les deux fichiers se trouvent dans le dossier « deps » du client gdata src .. nommé: google-collect-1.0-rc1.jar & jsr305.jar