1

当我尝试Typeface在我的类上使用这段代码创建一个新的Product(自定义类,具有getView()填充 a 的方法ListView

Typeface tf = Typeface.createFromAsset(context.getApplicationContext().getAssets(), "fonts/cambriab.ttf");

我得到以下堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.RuntimeException: native typeface cannot be made
    at android.graphics.Typeface.<init>(Typeface.java:175)
    at android.graphics.Typeface.createFromAsset(Typeface.java:149)
    at com.darkraven.shoppinglist.Category.getView(Category.java:133)
    at com.darkraven.shoppinglist.ProductListAdapter.getView(ProductListAdapter.java:40)
    at android.widget.AbsListView.obtainView(AbsListView.java:2179)
    at android.widget.ListView.makeAndAddView(ListView.java:1840)
    at android.widget.ListView.fillDown(ListView.java:675)
    at android.widget.ListView.fillFromTop(ListView.java:736)
    at android.widget.ListView.layoutChildren(ListView.java:1641)
    at android.widget.AbsListView.onLayout(AbsListView.java:2014)
    at android.view.View.layout(View.java:14290)
    at android.view.ViewGroup.layout(ViewGroup.java:4562)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
    at android.view.View.layout(View.java:14290)
    at android.view.ViewGroup.layout(ViewGroup.java:4562)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14290)
    at android.view.ViewGroup.layout(ViewGroup.java:4562)
    at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
    at android.view.View.layout(View.java:14290)
    at android.view.ViewGroup.layout(ViewGroup.java:4562)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14290)
    at android.view.ViewGroup.layout(ViewGroup.java:4562)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5124)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

上下文是主要的Activity

4

1 回答 1

0

如果您将 ttf 文件放在 assets 的 fonts 文件夹中,即使下面的代码也可以使用,或者我可以说它对我有用::

Typeface helveticaMedCond = Typefaces.get(getApplicationContext(), "fonts/Helvetica 67 Medium #2BD9AB.TTF");

在交叉验证您是否使用放置在字体文件夹中的相同字体名称之前。

于 2013-08-29T14:02:12.037 回答