Eclipse ClassCastException when trying to expand XML layout for Android

别等时光非礼了梦想. 提交于 2019-12-04 10:29:06

Workaround: I have found that if I catch and ignore the ClassCastException, and obviously then don't try to do anything with the View I was trying to find, there are no further problems and I can use the layout editor again: the editor will quite happily load, initialise and draw the problematic view, you just can't cast to its class.

try {
    picker = (NumberPicker) findViewById(R.id.myPicker);
    picker.blargh();
    // everything else involving picker
} catch (ClassCastException issue6894) {}  // ignore

If this is similar to the bug at http://code.google.com/p/android/issues/detail?id=6894 (ie the custom view loads another custom view), then the problem is likely due to the custom class loader that loads the custom view classes.

you can use View.isInEditMode (only returns true when your code is running inside eclipse) if you want to properly differentiate between running inside Eclipse or inside Android.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!