我正在创建一个小部件来访问存储在Google日历中的事件。 目标:Android 2.1
我已经包含了以下外部jar:
google-collect-1.0-rc1.jar jsr305.jar
GDATA个历2.0.jar,
GDATA个历元2.0.jar,
GDATA-客户1.0.jar,
GDATA客户端 - 间 - 1.0.jar,
GDATA核-1.0.jar
我得到以下异常:
com.google.gdata.util.ParseException : org.xml.sax
这是我的代码:HelloWidget.java
package de.thesmile.android.widget2;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.util.Log;
import android.widget.RemoteViews;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import de.thesmile.android.widget2.R;
public class HelloWidget extends AppWidgetProvider {
int number =0;
public String gooleres()
{
String result=new String("Unable to login into your account");
// Create a CalenderService and authenticate
try
{
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2011-03-01T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2011-03-06T23:59:59"));
CalendarService myService = new CalendarService("wqewq");
myService.setUserCredentials("sunnycool333@gmail.com", "XXXXXX");
//Send the request and receive the response:
Feed resultFeed = myService.query(myQuery, Feed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
result= entry.getTitle().getPlainText().toString();
}
}
catch(Exception e)
{
result="Exception raised "+e.toString();
}
return result;
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.main);
views.setTextViewText(R.id.widget_textview, gooleres());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
代码似乎是正确的,因为当我尝试将相同的代码作为简单的java文件然后我得到输出.. 我创建的简单java文件看起来像这样,它提供了正确的输出..
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create a CalenderService and authenticate
try
{
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2011-03-01T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2011-03-08T23:59:59"));
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("sunnycool333@gmail.com", "ytrfvgb$");
// Send the request and receive the response:
Feed resultFeed = myService.query(myQuery, Feed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
System.out.println(Integer.toString(i)+entry.getTitle().getPlainText().toString());
}
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e.toString());
}
}
答案 0 :(得分:1)
所以必须转移到谷歌java客户端库:(