3

I am getting an error when trying to load an asset from the resource folder:

NinePatchDrawable ninePatchObj = ((NinePatchDrawable) context.getResources().getDrawable(R.drawable.orange_btn));

Returns

java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable

This asset works properly when using the XML button object.

Thank you for any help provided.

kabuko
  • 36,028
  • 10
  • 80
  • 93
chris w.
  • 51
  • 3
  • check [this](http://stackoverflow.com/questions/5079868/create-a-ninepatch-ninepatchdrawable-in-runtime) and it maybe help you. – Simon Dorociak Jun 11 '12 at 21:59

2 Answers2

2

The actual issue was with the image.9.png a black line on the top and left side + "start and end" black dots on the bottom and right side were not sufficient (even though tutorials had indicated they would be).

Once a solid black marker was added to all sides of the image the chunk data would not be null and the NinePatchDrawable was successfully created.

chris w.
  • 51
  • 3
0

I solved a similar problem with my own image.9.png by making sure that the bottom black line is smaller than the top black line, and that the right black line is smaller than the left black line. This is because the area in which the text can be drawn should be smaller than the resizable part of the shape.

Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101