テキストビューのカスタムフォントフェイスをフラグメントに設定しようとしています。私はいくつかのtutsを見て、いくつかのstackoverflowの質問もトラバースし、カスタムフォントを使用してフォントフェイスを設定しようとしましたが、エラーが発生しました. フォント ファイルを「assets/fonts」フォルダーに配置しました。
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_one, null);
String fontPath = "fonts/AGENCYR.ttf";
// text view label
TextView txtGhost = (TextView) root.findViewById(R.id.featured_tourname);
// Loading Font Face
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), fontPath);
// Applying font
txtGhost.setTypeface(tf);
return root;
}
これは私のlogcat出力です:
07-06 18:10:47.834: E/Trace(1372): error opening trace file: No such file or directory (2)
07-06 18:11:11.122: E/AndroidRuntime(1372): FATAL EXCEPTION: main
07-06 18:11:11.122: E/AndroidRuntime(1372): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.travelplanner/com.example.travelplanner.FeaturedTourActivity}: java.lang.RuntimeException: native typeface cannot be made
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.os.Looper.loop(Looper.java:137)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-06 18:11:11.122: E/AndroidRuntime(1372): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 18:11:11.122: E/AndroidRuntime(1372): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 18:11:11.122: E/AndroidRuntime(1372): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-06 18:11:11.122: E/AndroidRuntime(1372): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-06 18:11:11.122: E/AndroidRuntime(1372): at dalvik.system.NativeStart.main(Native Method)
07-06 18:11:11.122: E/AndroidRuntime(1372): Caused by: java.lang.RuntimeException: native typeface cannot be made
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.graphics.Typeface.<init>(Typeface.java:175)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.graphics.Typeface.createFromAsset(Typeface.java:149)
07-06 18:11:11.122: E/AndroidRuntime(1372): at com.example.travelplanner.FragmentOne.onCreateView(FragmentOne.java:29)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.Activity.performStart(Activity.java:5114)
07-06 18:11:11.122: E/AndroidRuntime(1372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
07-06 18:11:11.122: E/AndroidRuntime(1372): ... 11 more
どんな助けでも大歓迎です..