0

I have followed this SO (excepted answer) and added FontAwesome.otf to assets/fonts folder here are my strings:

<!-- icons -->
    <string name="list_icon">&#xf03a;</string>
    <string name="plus_icon">&#xf067;</string>
    <string name="search_icon">&#xf002;</string>

Here are the buttons:

<Button
            android:id="@+id/b1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/navigation_button"
            style="?android:attr/buttonBarButtonStyle" 
            android:textColor="#FFFFFF"
            android:text="@string/search_icon" />

        <Button
            android:id="@+id/b2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/navigation_button"
            style="?android:attr/buttonBarButtonStyle"
            android:textColor="#FFFFFF"
            android:text="@string/plus_icon" />

        <Button
            android:id="@+id/b3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/navigation_button"
            style="?android:attr/buttonBarButtonStyle"
            android:textColor="#FFFFFF" 
            android:text="@string/list_icon" />

and here is the typface:

font = Typeface.createFromAsset(getAssets(), "/fonts/FontAwesome.otf" );

and here is the buttons again:

        B1 = (Button) findViewById(R.id.b1);
        B2 = (Button) findViewById(R.id.b2);
        B3 = (Button) findViewById(R.id.b3);

        B1.setTypeface(font);
        B2.setTypeface(font);
        B3.setTypeface(font);

Here is the logcat:

01-28 00:15:34.863: E/AndroidRuntime(1933): FATAL EXCEPTION: main
01-28 00:15:34.863: E/AndroidRuntime(1933): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evapp.activities/com.evapp.activities.HomeActivity}: java.lang.RuntimeException: native typeface cannot be made
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.os.Looper.loop(Looper.java:137)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at java.lang.reflect.Method.invokeNative(Native Method)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at java.lang.reflect.Method.invoke(Method.java:511)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at dalvik.system.NativeStart.main(Native Method)
01-28 00:15:34.863: E/AndroidRuntime(1933): Caused by: java.lang.RuntimeException: native typeface cannot be made
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.graphics.Typeface.<init>(Typeface.java:175)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.graphics.Typeface.createFromAsset(Typeface.java:149)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at com.evapp.activities.HomeActivity.onCreate(HomeActivity.java:19)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.Activity.performCreate(Activity.java:5008)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-28 00:15:34.863: E/AndroidRuntime(1933):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

Here is screenshot of the fonts files:

What is wrong with that??

Community
  • 1
  • 1
vlio20
  • 8,955
  • 18
  • 95
  • 180

1 Answers1

1

I found differences with the lines of code below after looking at your referenced link. It seems like the referenced link just used the filename as a parameter whereas you are providing a path to the file. Also perhaps you want to declare font as a Typeface unless this is done earlier on in the code.

Your code...

font = Typeface.createFromAsset(getAssets(), "/fonts/FontAwesome.otf" );

Code from referenced link...

Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome-webfont.ttf" );
Josh Engelsma
  • 2,636
  • 14
  • 17
  • 1
    Also note that the link uses a TTF font, not an OTF font. – CommonsWare Jan 27 '14 at 22:32
  • I am declaring on font earlier so there is no `NullPointerException` as you can see the log. I also tried it with `fontawesome-webfont.ttf`, and it didn't work. I have also tried to put it in the assets file without the fonts file. – vlio20 Jan 27 '14 at 22:36
  • @VladIoffe did you change the filename/type of file in the assets folder and change the code when you tried it? Also is the error message the same after changing? – Josh Engelsma Jan 27 '14 at 22:38
  • Yes, the error is the same. I have added the location of my files. also I have changed from `"/fonts/FontAwesome.otf"` to `"fontawesome-webfont.ttf"` – vlio20 Jan 27 '14 at 22:40
  • ok sorry to ask again, want to make sure you got what I was telling you to do, but did you rename the file located in the assets/font folder FontAwesome.otf to fontawesome-webfont.ttf – Josh Engelsma Jan 27 '14 at 22:44
  • Yes, it works after I deleted everything and started from scratch... odd but true. I believe there was something fonts file location. – vlio20 Jan 27 '14 at 22:46
  • The problem now is that I can't see any icon :( – vlio20 Jan 27 '14 at 22:47
  • Hey one step at a time :) so no error messages but no icons either? – Josh Engelsma Jan 27 '14 at 22:48
  • Why don't you delete the extra file FontAwesome.otf, are you sure the contents of the fontawesome-webfont.ttf are the correct contents? – Josh Engelsma Jan 27 '14 at 23:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46195/discussion-between-vlad-ioffe-and-josh-engelsma) – vlio20 Jan 28 '14 at 06:42