2016-09-30 12 views
0

特定のフォントのカスタムテキストビュークラスがあります。カスタムTextViewのレンダリングエラー

私のクラス: `

public LobsterTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf"); 
    this.setTypeface(face); 
} 

public LobsterTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf"); 
    this.setTypeface(face); 
} 

}

私のレイアウト:

<x.y.z.LobsterTextView 
     android:id="@+id/tv_mobile_name" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:textSize="@dimen/font_large3" 
     android:layout_marginTop="@dimen/fab_margin" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:textColor="@color/colorAccent_3" 
     android:text="Register with Pika" /> 

とエラー:`レンダリングの問題以下のクラスをインスタンス化することができませんでした: - io.pika。 pike_store.utils.LobsterTextView(クラスを開く、例外を表示する、キャッシュをクリアする) ヒント:カスタムビューでView.isInEditMode()を使用すると、コードやスキップをスキップできますIDEに表示されるサンプルデータの詳細例外の詳細java.lang.NullPointerException android.graphics.Typeface.createAssetUid(Typeface.java:219)android.graphics.Typeface.createFromAsset(Typeface.java:193)at io.pika android.viewのandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)のjava.lang.reflect.Constructor.newInstance(Constructor.java:423)のpike_store.utils.LobsterTextView(LobsterTextView.java:22)。 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:834)のandroid.view.LayoutInflater_Delegate.rInflate(LayoutInflater.java:858)をandroid.view.LayoutInflater.rInflate(LayoutInflater.java:834)に配置します。LayoutInflater.rInflater_Original(LayoutInflater.java:858) (LayoutInflater.java:834)のandroid.view.LayoutInflater.rInflater_Original(LayoutInflater.java:861)のandroid.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)のandroid.view.LayoutInflater.rInflateアンドロでandroid.view.LayoutInflater.parseInclude(LayoutInflater.java:821)android.view.LayoutInflater.parseInclude(LayoutInflater.java:821)android.view.LayoutInflaterのandroid.view.LayoutInflater.parseInclude(LayoutInflater.java:902)のandroid.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:197)のid.view.LayoutInflater.rInflateChildren 。android.view.LayoutInflater.rInflaterChildren(LayoutInflater.java:834)のandroid.view.LayoutInflater_Delegate.rInflate(LayoutInflater.java:854)をandroid.view.LayoutInflater.rInflate(LayoutInflater.java:834)の.rInflate_Original(LayoutInflater.java:854)に設定します。 android.view.LayoutInflater.inflate(LayoutInflater.java:397)スタックをクリップボードにコピーLobsterTextViewカスタムビューは、最後のものよりも最近編集されていますbuild:プロジェクトをビルドします。

一度実行したコードは正常に動作しますが、レイアウトファイルに来ると、このエラーは常にフォアグラウンドになります。

どのように私は問題を解決できますか? `

答えて

0

パブリッククラスPahariTextViewはTextViewにpahari @ {

public PahariTextView(Context context) { 
    super(context); 

    applyCustomFont(context); 
} 

public PahariTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 

    applyCustomFont(context); 
} 

public PahariTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 

    applyCustomFont(context); 
} 

private void applyCustomFont(Context context) { 
    Typeface customFont = FontCache.getTypeface("fonts/quicksand_light.otf", context); 
    setTypeface(customFont); 
} 

}

+0

、応答pahariに感謝を拡張します。まだ同じ問題を抱えており、あなたのコードと私のコードの間に違いはありません。 –

+0

詳細を記述してください。 –

+0

private void applyCustomFont(コンテキストコンテキスト){ タイプフェイスcustomFont = FontCache.getTypeface( "fonts/quicksand_light.otf"、context); setTypeface(customFont); –

関連する問題