Android Studio and ADT have different TypedArray values -
i have app build android studio , adt. adt others able build , run. myself use android studio. when else added custom ui control, android studio's version crash in ui has custom control in it. after intensive debugging, found out it's in android studio, typedarray of custom control has different values adt's version. how happen? did countless google search without success. can help?
specifically, it's getdimension(int index, float defvalue)
throwing exception, code of below:
public float getdimension(int index, float defvalue) { index *= assetmanager.style_num_entries; final int[] data = mdata; final int type = data[index+assetmanager.style_type]; if (type == typedvalue.type_null) { return defvalue; } else if (type == typedvalue.type_dimension) { return typedvalue.complextodimension( data[index+assetmanager.style_data], mresources.mmetrics); } throw new unsupportedoperationexception("can't convert dimension: type=0x" + integer.tohexstring(type)); }
you can see it's type of index not type_dimension. here issue mdata
, member of typedarray
class, have different value adt compiled apk file @ runtime. weird. thing custom ui control in form of jar file, not in source code form. guess it's android studio did generated dex code caused issue.
update: after upgrading android studio 0.5.9 android studio 0.5.8, location of exception changed slightly. it's getfloat
throwing exception. below source code of getfloat
/** * retrieve float value attribute @ <var>index</var>. * * @param index index of attribute retrieve. * * @return attribute float value, or defvalue if not defined.. */ public float getfloat(int index, float defvalue) { index *= assetmanager.style_num_entries; final int[] data = mdata; final int type = data[index+assetmanager.style_type]; if (type == typedvalue.type_null) { return defvalue; } else if (type == typedvalue.type_float) { return float.intbitstofloat(data[index+assetmanager.style_data]); } else if (type >= typedvalue.type_first_int && type <= typedvalue.type_last_int) { return data[index+assetmanager.style_data]; } typedvalue v = mvalue; if (getvalueat(index, v)) { log.w(resources.tag, "converting float: " + v); charsequence str = v.coercetostring(); if (str != null) { return float.parsefloat(str.tostring()); } } log.w(resources.tag, "getfloat of bad type: 0x" + integer.tohexstring(type)); return defvalue; }
the error happens @ line:
charsequence str = v.coercetostring(); if (str != null) { return float.parsefloat(str.tostring()); }
due incorrect type
value caused incorrect mdata
retrieved style attributes file, str becomes
@2131296258
instead of correct value
2131296258
so parsefloat
complaining invalid float value.
as can see, root cause incorrect value style attributes in android studio. thoughts on how fix it?
***btw, adt version worked flawless. it's android studio version crashes whenever custom ui widget
update 2: question partially answered in form of comments. it's not resolved. i'll leave in case else needs information.
Comments
Post a Comment