tags:

views:

119

answers:

1

Hi All,

I am trying to use custom font in android. I have written java code as given below.

TextView txt = (TextView) findViewById(R.id.customfont);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
txt.setTypeface(font);

where I have stored the custom font in "./assets/fonts/" folder.

But, I am getting nullpointerexception on the 3rd line.

Can anybody give me the solution for this issue? Thanks

+1  A: 

Android supports only TTF font type not OTF. Check this link

http://stackoverflow.com/questions/3023960/crash-when-loading-font

Rahul
Thanks a Lot! But I tried even using .ttf, it doesn't work yet...and still throws the same exception
RATTLESNAKE
Please note that the Font name you are entering is case sensitive. If you are still stuck up i probably think it should be a issue with the Font file you are using. Try downloading a different font TTF file and loading it.After a quick googling i found this website which can convert OTF to TTF. May be you can give a try http://onlinefontconverter.com/
Rahul
You can also check this post which has a sample project associated with it... http://stackoverflow.com/questions/3203694
Rahul
hey! I tried it out, but it's still not working
RATTLESNAKE
Did you download the sample project available with the above link and try running it?..it should work http://github.com/commonsguy/cw-android/tree/master/Fonts/FontSampler/
Rahul
yes, but it's not working
RATTLESNAKE