我的代码崩溃了,我需要一些帮助。除了这部分,一切都运行良好。
没有错误,但它在timer.schedule(loadImg2, 5000);
那之前崩溃了if (!c.moveToNext())
我的问题:我是否在循环中正确使用了计时器?因为那是代码崩溃的地方。
我从来没有看到这个日志"+-+-+-+-+-+-+-+-+- Getting out "
或之后的任何东西。
do
{
Log.v("log_tag", "+-+-+-+-+-+-+-+-+- Ttrying to cancel ");
//timer.cancel();
Log.v("log_tag", "+-+-+-+-+-+-+-+-+- Timer canceled ");
timer = new Timer();
Log.v("log_tag", "+-+-+-+-+-+-+-+-+- New timer created ");
//delay amount of time(5s here) in milliseconds before first execution.
//period amount of time(1s here) in milliseconds between subsequent executions.
timer.schedule(loadImg2, 5000); //this did not produce any effect so far
if (!c.moveToNext())
{
//destroy
timer.cancel();
myImageView.setImageBitmap(null);
Log.v("log_tag", "+-+-+-+-+-+-+-+-+- Getting out ");
//get out of the loop or set c.moveToFirst()
break;
}
} while (true);
TimerTask loadImg2 = new TimerTask()
{
@Override
//Load Img2
public void run()
{
runOnUiThread(new Runnable()
{
public void run()
{
Log.v("log_tag", "+-+-+-+-+-+-+-+-+- Inside loadImg2 ");
titleText.setText(DisplayTitle(c));
Bitmap bitmap2 = BitmapFactory.decodeFile(c.getString(5));
myImageView = (ImageView) findViewById(R.id.imageview1);
myImageView.setImageBitmap(null);
timer.cancel();
}
});
}
}