java同步标记_java – 线程/处理程序错误 – 尚未发布指定的消息队列同步屏障标记...

我收到此错误 –

java.lang.IllegalStateException: The specified message queue synchronization barrier token has not been posted or has already been removed.

作为Java / Android的相对新手,毫无疑问我错过了一些东西,但我正在做的是这个 –

我有一个项目使用Exif数据根据拍摄日期显示照片,目的是在每个舞台上使用类似的模型……

工人线程 – > UI线程 – >定制显示适配器.然后单击GridView中的一个“单元格”将触发下一个活动.第一个活动搜索所有照片文件,创建“年”列表,然后每个后续活动将其过滤到几个月,几天等.

但是,启动第二个活动会直接启动上述错误,并通过基本的线程/处理程序设置处理消息.

这是将消息传递给线程的类 –

public class MonthSort {

Handler handler;

int imageWidth;

List photoList;

public MonthSort(Handler handler2,int width,List pList) {

photoList = new ArrayList();

photoList = pList;

imageWidth = width;

handler = handler2;

}

public void sortFiles()

{

int month,photoCount;

File fileName = new File("");

Message msg = handler.obtainMessage();

//Message msg = Message.obtain();

//Bundle bundle = new Bundle();

try {

for (int i = 0; i < 12; i++) {

month = i + 1;

photoCount = 0;

for (PhotoData pd : photoList) {

if(month == pd.month)

{

if(photoCount == 0)

fileName = pd.fileName;

photoCount++;

}

}

if(photoCount != 0)

{

Bundle bundle = new Bundle();

bundle.putString("filename",fileName.toString());

bundle.putInt("month",month);

bundle.putInt("count",photoCount);

byte[] thumbNail = getThumbnail(fileName,imageWidth);

bundle.putByteArray("thumbnail",thumbNail);

msg.setData(bundle);

handler.sendMessage(msg);

}

}

} catch (Exception e) {

// TODO Auto-generated catch block

Log.d("Debug","handler error occurs in monthSort class");

}

/*Bundle bundle = new Bundle();

bundle.putBoolean("end",true);

msg.setData(bundle);

handler.sendMessage(msg);*/

}

…这是在UI线程中接收它的代码.

public class MonthActivity extends Activity {

List photoList;

static List photos;

int imageWidth;

GridView photoGrid;

static ImageAdapter2 iAdapter;

int year;

Thread monthSortThread;

Handler handler2 = new Handler() {

@Override

public void handleMessage(Message msg)

{

Bundle bundle = msg.getData(); // Get the message sent to the Handler.

boolean ended = bundle.getBoolean("end");

if(ended)

{

//Toast.makeText(getBaseContext(),"FINISHED !!!",Toast.LENGTH_LONG).show();

} else

{

try {

MonthData md = new MonthData();

md.monthValue = bundle.getInt("month");

md.monthString = getMonthString(md.monthValue);

md.count = bundle.getInt("count");

byte[] tn = bundle.getByteArray("thumbnail");

md.thumbnail = BitmapFactory.decodeByteArray(tn,tn.length);

photos.add(md);

iAdapter.notifyDataSetChanged();

} catch (Exception e) {

// TODO Auto-generated catch block

Log.d("Debug","handler error occurs in UI Handler");

}

}

}

};

请注意,我没有包含所有代码,只是我觉得相关的部分.

之前的活动成功地以相同的方式操作消息,为什么不是第二个活动?

我知道主UI线程已经有一个looper设置,因此你不必创建一个.是否仍然适用于任何后续活动?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值