Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

java - Font asset not found helvetica.ttf on lollipop

For some reason on lollipop, I'm getting this error and since lollipop is so new I can't find out why anywhere and I have no idea how to figure it out. Thanks in advance Logcat error:

java.lang.RuntimeException: Unable to start activity                                       
ComponentInfo{com.bent.MissionaryTracker/com.bent.MissionaryTracker.MainActivity}:          
java.lang.RuntimeException: Font asset not found helvetica.ttf
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.RuntimeException: Font asset not found helvetica.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
at com.bent.MissionaryTracker.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
... 10 more

EDIT: HERE IS THE CODE THAT THROWS THE ERROR

    title = (TextView) findViewById(R.id.title);


    Typeface font = Typeface.createFromAsset(getAssets(), "helvetica.ttf");
    title.setTypeface(font);

I have helvetica.ttf in my assets folder in my project folders.

EDIT: This app works on all devices up until 5.0 so for some reason 5.0 is not recognizing the file in my assets folder.

I tried to post a screenshot of it in my assets folder but I don't have enough reputation to post images.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are working on Android Studio make sure your asset folder is under main and not res This worked for me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...