VerifyError deploying on API 1.6

こ雲淡風輕ζ 提交于 2019-11-28 07:38:10

When Dalvik compiles your class/function from bytecode into native machine code, it compiles all statements, even those that are inside if conditions. On Android 1.6 virtual machine tries to resolve (verify) getActionBar function, and since there is no such function, Dalvik throws VerifyError.

You can do next trick:

class ActionBarHelper{
   void setBackground(){
      getActionBar().setBackgroundDrawable(...);
   }
}

...

if(android.os.Build.VERSION.SDK_INT >= 11) {
   new ActionBarHelper().setBackground();    
}

This way ActioBarHelper class will only be compiled/verified when you're running on SDK 11+. This will in turn allow calling getActionBar function without using reflection (reflection is another possible solution to this problem).

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