我的小部件有问题: 这是代码:
public class HelloWidget extends AppWidgetProvider {
public long t=0,lastUpdate=0;
public int scor1[],scor2[],teams,displayPage=0;
public String team1[],team2[];
Bitmap b1;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1000, 10000);
}
private class MyTime extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
java.text.DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM,Locale.getDefault());
public MyTime(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
thisWidget = new ComponentName(context, HelloWidget.class);
}
@Override
public void run() {
remoteViews.setTextViewText(R.id.Clock,format.format(new Date()));
checkUpdate();
b1= BitmapFactory.decodeFile("/sdcard/crests/" + team1[displayPage*2] + ".png");
b1=Bitmap.createScaledBitmap(b1, 54, 54, true);
remoteViews.setImageViewBitmap(R.id.team11,b1);
b1= BitmapFactory.decodeFile("/sdcard/crests/" + team2[displayPage*2] + ".png");
b1=Bitmap.createScaledBitmap(b1, 54, 54, true);
remoteViews.setImageViewBitmap(R.id.imageView4,b1);
b1= BitmapFactory.decodeFile("/sdcard/crests/" + team1[displayPage*2 + 1] + ".png");
b1=Bitmap.createScaledBitmap(b1, 54, 54, true);
remoteViews.setImageViewBitmap(R.id.imageView3, b1);
b1= BitmapFactory.decodeFile("/sdcard/crests/" + team2[displayPage*2 + 1] + ".png");
b1=Bitmap.createScaledBitmap(b1, 54, 54, true);
remoteViews.setImageViewBitmap(R.id.imageView2, b1);
remoteViews.setTextViewText(R.id.textView4, team1[displayPage*2]);
remoteViews.setTextViewText(R.id.textView1, team2[displayPage*2]);
remoteViews.setTextViewText(R.id.textView2, team1[displayPage*2 + 1]);
remoteViews.setTextViewText(R.id.textView6, team2[displayPage*2 + 1]);
remoteViews.setTextViewText(R.id.textView3, Integer.toString(scor1[displayPage*2]));
remoteViews.setTextViewText(R.id.textView8, Integer.toString(scor2[displayPage*2]));
remoteViews.setTextViewText(R.id.textView5, Integer.toString(scor1[displayPage*2 + 1]));
remoteViews.setTextViewText(R.id.textView7, Integer.toString(scor2[displayPage*2 + 1]));
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
}
但是当我把它放在屏幕上时它强行关闭。我在logcat中收到以下消息: 显示java.lang.NullPointerException 在HelloWidget $ MyTime.run
问题是什么?我该如何解决?