此代码生成以下错误。有谁知道为什么?谢谢!
java.lang.NoClassDefFoundError: android.provider.Settings$Global
@SuppressLint( "NewApi" )
@SuppressWarnings("deprecation")
public boolean isAirplaneModeOn(Context context) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0; //<--Error here
} else {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
}
答案 0 :(得分:1)
您应该检查以下内容:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
因为该类是在API级别17中引入的,即Build.VERSION_CODES.JELLY_BEAN_MR1。或者你可以这样做:
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN){