IT TIP

글꼴을로드 할 때 "RuntimeException : 기본 서체를 만들 수 없습니다"

itqueen 2020. 11. 21. 08:29
반응형

글꼴을로드 할 때 "RuntimeException : 기본 서체를 만들 수 없습니다"


여기 가이드에 따라 Android의 TextView에 사용자 지정 글꼴을 사용하려고합니다 . 동일한 글꼴, 동일한 코드, 동일한 모든 것을 사용하여 adb logcat에 다음과 같이 표시됩니다.

W/dalvikvm(  317): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(  317): FATAL EXCEPTION: main
E/AndroidRuntime(  317): java.lang.RuntimeException: Unable to start activity  ComponentInfo{org.evilx.quacklock/org.evilx.quacklock.MainActivity}:             java.lang.RuntimeException: native typeface cannot be made
E/AndroidRuntime(  317):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  317):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  317):        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  317):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  317):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  317):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  317):        at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  317):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  317):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  317):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  317):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  317):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  317): Caused by: java.lang.RuntimeException: native typeface cannot be made
E/AndroidRuntime(  317):        at android.graphics.Typeface.<init>(Typeface.java:147)
E/AndroidRuntime(  317):        at android.graphics.Typeface.createFromAsset(Typeface.java:121)
E/AndroidRuntime(  317):        at org.evilx.quacklock.MainActivity.onCreate(MainActivity.java:24)
E/AndroidRuntime(  317):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  317):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  317):        ... 11 more
W/ActivityManager(   59):   Force finishing activity org.evilx.quacklock/.MainActivity
W/ActivityManager(   59): Activity pause timeout for HistoryRecord{43e80368 org.evilx.quacklock/.MainActivity}
D/dalvikvm(  247): GC_EXPLICIT freed 711 objects / 53160 bytes in 20922ms

블로그 중 하나에서 성공적으로 사용 된 Molot.otf 글꼴을 사용하고 있습니다. 또 다른 사용자 지정 글꼴이지만 TrueType 형식 인 predator.ttf도 사용하고 있습니다.

관련 코드 :

public class MainActivity extends Activity {
    // Called when the activity is first created.
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
        TextView tv = (TextView) findViewById(R.id.CustomFontText);
        tv.setTypeface(tf);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/CustomFontText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:text="Here is some text.">
    </TextView>
</LinearLayout>

원인은 무엇입니까? 블로그에있는 사람들을 위해 일한 것입니다. 그래서 저는 왜 안됩니까? 이 작업을 방해하는 API에 중요한 변경 사항이 있습니까?


Android does not support OpenType (OTF), only TrueType (TTF), so your Molot.otf font probably will not work. I wrote both of those blog posts you link to in your opening sentence (the one is a pirated copy of the other), and they do not use Molot.otf.

(BTW, I somewhat repaired the formatting of that post -- AndroidGuys keeps changing WordPress hosts, and so my older posts are terribly broken in terms of formatting).

EDIT: As stated in the comments, Android DOES now support OTF.


I also get the same error and I have solution follow.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf")

you must put fonts/Molot.otf in assets/fonts folder in your Eclipse.

after you can Run it.

if you can not Run it successfull you can send proplem via


Unfortunately, the typeface cannot be made error is not very specific, and it can be the result of many things going wrong. It's important to check for two things:

  • The first and most important: The file is found!
  • The font is valid in your device.

The best way is to change your font file for a known valid font file.
If it fails, then it's the first problem.
If not, it's the second, so you will have to deal with FontForge or look for another font.


check font's name and extension. it is case sensitive & probably all caps. eg.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MOLOT.OTF")

FYI. My reason for the crash is some reason caused by Eclipse. All I did is just cleaning the project and ran again, then it works.

Firstly, I tried the custom font in my test project which I use to try some new functions.It worked on the very first time. But it didn't work on the project i'm working on until I did as above.

So try as many methods as you can.


Android does support OTF files for Typefaces, if you're facing this problem, make sure that you're setting the right path for the font.put font into folder fonts inside assets folder and create the typeface as below :

Typeface typeface = Typeface.createFromAsset(getAssets(), "font/StencilStd.otf");
TextView text = (TextView) findViewById(R.id.textView);
text.setTypeface(typeface);

@deng his answer worked for me":

check font's name and extension. it is case sensitive & probably all caps. eg.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MOLOT.OTF")

You should edit your font with 'Fontlab' Software in binary mod.


Android does support OTF files for Typefaces, if you're facing this problem, make sure that you're setting the right path for the font, for example, if you have the file fontname.otf, put it in a folder fonts inside assets folder and create the typeface like follows :

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/fontname.otf");

(path argument should not start with "/") and the file name should not include special characters or a "-" and should be in lowercases

참고URL : https://stackoverflow.com/questions/3023960/runtimeexception-native-typeface-cannot-be-made-when-loading-font

반응형