Tuesday, 15 May 2012

android - Resources$NotFoundException: resource ID not valid. Why? -


I am trying to add float to my dimens.xml file.

I was reading. When I tried the solution, I got the exception mentioned in the comments. I am trying to understand why why that exception has been thrown away.

Here is the XML for completion:

    

Here's the code that's going on:

  last float zoom = this.getResources (). GetDimension (R.dimen.zoom_level);   

I jumped into the Android source, and here is the method definition for getDimension:

  get public float (difference ID) throws NotFoundException {synchronize (mTmpValue) )) {Value of the typed value = mTmpValue; GetValue (id, value, true); If (value.type == typed value. TYPE_DIMENSION) {TypedValue.complexToDimension (value.data, mMetrics); } New NotFoundException Throw ("Resource ID # 0x" + Integer.TaxStrin (ID) + "Type # 0x" + Integer. TextString (Value Type) + "Not Valid"); }}   

So whatever the reason value.type! = Typed value TYPE_DIMENSION . I do not have my Android source fully set, so I can not easily add the Log.w ("YARIAN", "value type" + value.type) ' statement.

Then I jumped into getValue and finds a series of calls:

  resources.getValue -> AssetManager.getResourceValue - & gt; AssetManager.loadResourceValue   

loadResourceValue is an original method and here's where my excavation is different.

Does anyone know what is the best way to do what is happening?


I also noticed that the value typed in a in resource . Typpa Floyd and typed value. TYPE_DIMENSION . But in XML, I can not write type = "float" .

Use type = string for the work described in the comments and then use it to get the float float.from is it necessary? Why not and why not?

I know that this is a late reply, but you use it instead of parsing the string Should you have a float like you suggested.

XML:

  & lt; Item name = "float_source" format = "float" type = "raw"> 5.0 & lt; / Item & gt;   

Java:

  typed value = new typed value (); Context.getResources (). GetValue (R.raw.float_resource, outside, true); Float float resource = out.get float ();   

You enter fraction , raw or string as the type If you want, then it only matches the resource class in R .

No comments:

Post a Comment