title: RuntimeException: native typeface cannot be made or memory leak for custom TextView loading font
body: <p>There's a HUGE problem in my code wherein I am loading a font in my <code>assets\fonts\</code> folder from a custom <code>TextView</code> class. The first problem is that it crashes on 4.0 devices with the exception <code>Caused by: java.lang.RuntimeException: native typeface cannot be made</code>. I was using the same process <a href="http://alinberce.wordpress.com/2012/01/25/using-custom-fonts-in-android-bold-italic-regular-you-name-it/" rel="nofollow noreferrer">here</a> with the method:</p>
  
  <pre><code>public class MyTextView extends TextView {
  
        public MyTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
  
       public MyTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
  
       public MyTextView(Context context) {
            super(context);
       }
  
  
      public void setTypeface(Typeface tf, int style) {
          if (style == Typeface.BOLD) {
              super.setTypeface(Typeface.createFromAsset(
                      getContext().getAssets(), "fonts/hirakakupronbold.ttf"));
          } else if (style == Typeface.ITALIC) {
              super.setTypeface(Typeface.createFromAsset(
                      getContext().getAssets(), "fonts/hirakakupronitalic.ttf"));
          } else {
              super.setTypeface(Typeface.createFromAsset(
                      getContext().getAssets(), "fonts/hirakakupron.ttf"));
          }
      }
  }
  </code></pre>
  
  <p>Notice that I'm using the extension <code>.ttf</code>, and I found that this is causing the <code>RunTimeException</code>. So I converted the respective fonts with a <code>.otf</code> extensions, and now it runs already in 4.0 devices but has memory leaks basing <a href="https://stackoverflow.com/a/7197867/1968739">here</a>. There are workarounds <a href="https://code.google.com/p/android/issues/detail?id=9904" rel="nofollow noreferrer">here</a> but I don't know how to use/call it. Any help would do, thank you.</p>