-1

I am developing my app with Maven build tool.. In my assets folder I have fonts/DroidSansFallback.ttf..

And my activity_main.xml is:--

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bck54"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="99dp"
        android:layout_marginTop="78dp"
        android:text="hello world" />

</RelativeLayout>

and my HelloAndroidActivity.java is:--

public class HelloAndroidActivity extends Activity {

    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Typeface tf = Typeface.createFromAsset(getAssets(),
                "fonts/DroidSansFallback.ttf");
         tv = (TextView) findViewById(R.id.textView1);
         tv.setTypeface(tf);

    }


}

Here I want to change my text fonts..But the app is stopped.. My logcat error is:--

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arijit.patra.love/com.arijit.patra.love.HelloAndroidActivity}: java.lang.RuntimeException: native typeface cannot be made
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2346)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2398)
    at android.app.ActivityThread.access$800(ActivityThread.java:159)

Can anyone tell me where is the problem??

user_apr
  • 719
  • 2
  • 10
  • 27

2 Answers2

0

Are you created a folder called fonts in assets or directly placed in assets folder??if folder not created create a folder and place your font file there I think that is the mistake..In your example he is not created any fonts folder he is directly accessing but you are accessing from fonts folder..

If not fonts folder then change this line to.

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/amal.TTF");

like this..

Typeface font = Typeface.createFromAsset(getAssets(), "amal.TTF");

it its not working than,

The font file is either corrupt or unsupported for some reason.

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19
0

may be your font file is corrupted that's why you get this error message. delete that file and download again from somewhere else and put it again in your asset folder.

Prashant Jajal
  • 3,469
  • 5
  • 24
  • 38
  • Thnx..Now its working..is there any other way where I can change the fonts xml..I mean 2 say not in run time..In run time there is a problem to set the texts..is there any other way? – user_apr Nov 29 '14 at 09:14
  • for that you need to make your Custom textView then you can change font in xml. and note that when you add your custom textView in xml at that time you can not see the font change reflaction , it shown only at run time. – Prashant Jajal Nov 29 '14 at 09:18