3

请帮忙。

Android: Unable to instantiate service...can't instantiate class com.stocktickerwidget.AppWidget$UpdateService; no empty constructor

我收到上面的错误,

我不懂为什么。

谢谢

public class UpdateService extends Service {
    public UpdateService() {
       //
        }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("", "onStartCommand di AppWidget");
        int[] appWidgetIds = intent.getIntArrayExtra("widgetsids");
        final int N = appWidgetIds.length;
        AppWidgetManager manager = AppWidgetManager.getInstance(this);

        // Perform this loop procedure for each App Widget that belongs to
        // this provider

        for (int i = 0; i < N; i++) {
            int appWidgetId = appWidgetIds[i];
            Log.e("",
                    "i=" + Integer.toString(i) + " di "
                            + Integer.toString(N));
            RemoteViews view = buildUpdate(getApplicationContext(),
                    appWidgetIds);

            // Tell the AppWidgetManager to perform an update on the current
            // app widget
            manager.updateAppWidget(appWidgetId, view);

        }
        return (START_NOT_STICKY);

    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
}
4

1 回答 1

10

首先,删除您的构造函数,因为您从Service.

然后,要么让它成为一个static内部类,要么让它成为一个独立的公共 Java 类。您不能在这里使用常规的内部类,因为 Android 无法创建该内部类的实例。

于 2013-03-27T14:06:05.190 回答