TextView
にTypeFace
を追加します。ここで私はこの設定TypeFace NullpointerException
0
A
答えて
2
問題はコンテンツビューを設定する前にfindViewById()
に電話していることです。
を暗黙的に呼び出します。そのときは、まだnull
です。あなたのView
を初期化前
コールsetContentView()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
TextView helptitle = (TextView)findViewById(R.id.title_help);
Typeface typeface = Typeface.createFromAsset(getAssets(), "beyond_the_mountains.ttf");
helptitle.setTypeface(typeface);
}
+0
ohhありがとう:) –
+0
あなたは大歓迎です:) – earthw0rmjim
2
を解決するかどうかはわかりませんNullPointerExceptionが多くの種類がありますが、私のJavaコード
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView helptitle = (TextView)findViewById(R.id.title_help);
Typeface typeface = Typeface.createFromAsset(getAssets(), "beyond_the_mountains.ttf");
helptitle.setTypeface(typeface);
setContentView(R.layout.activity_help);
}
だが、私はアプリを実行したとき、私は
Caused by: java.lang.NullPointerException
at com.example.enxin.crystallise.Help.onCreate(Help.java:15)
ログ猫のエラーを取得します
//You have mistaken the order
setContentView(R.layout.activity_help);
TextView helptitle = (TextView)findViewById(R.id.title_help);
Typeface typeface = Typeface.createFromAsset(getAssets(), "beyond_the_mountains.ttf");
helptitle.setTypeface(typeface);
関連する問題
- 1. SquareTextView TypeFaceの設定方法
- 2. RecyclerView Custom Typeface Adapter
- 3. なぜ "new"なしでオブジェクトを作成するのですか?Typeface typeface = new Typeface();?[1]:https://i.stack.imgur.com/h9HqN.png
- 4. NullPointerException動的ボタンのonClickEventを設定する
- 5. フラグメント内のonClickListenerを設定するとNullPointerExceptionが発生する
- 6. LayoutParamsの設定中にNullPointerExceptionが発生する
- 7. 設定ファイルでoteleporterを使用中にNullPointerExceptionが発生する
- 8. Apache NiFi - カスタムプロセッサで複数のスレッドを設定するNullPointerException
- 9. アンドロイドのNullPointerException:コンテキストを設定する方法?
- 10. androidのカスタムフォントを使用したNullPointerException
- 11. USBConnection nullPointerException
- 12. Android TypefaceにSharedPrefereceを使用するには?
- 13. nullPointerExceptionが設定されている場合、殺されたアプリケーションのアラームマネージャ
- 14. 設定のインテント呼び出し中にNullPointerExceptionが発生しました
- 15. NullPointerExceptionがlistViewをクリック可能に設定しようとしています
- 16. テキストフィールドのテキストを設定するときにNullPointerExceptionが発生する
- 17. NullPointerException配列のボタンに対してsetOnClickListenerを設定した場合
- 18. Android:ボタンをクリックすると画像を設定できません(NullpointerException/IllegalStateException)
- 19. コードが正しくても共有設定でNullPointerExceptionが表示される
- 20. 休止状態でSetを設定するとNullPointerExceptionが発生する
- 21. NullPointerException
- 22. `NullPointerException`
- 23. Mainクラスで@Autowieredを指定したNullPointerException
- 24. Android SharedPreferences getSharedPreferencesのNullPointerException
- 25. android.widget.Editor:SpannableStringInternalのNullPointerException
- 26. バインディングのNullPointerException
- 27. RecyclerViewアダプタのNullPointerException
- 28. NullPointerExceptionでフラグメント関数
- 29. SpringテストとNullPointerException
- 30. NullPointerException SupportMapFragment.getMapAsync
最初のメイクコールsetContentView(R.layout.activity_help)。次にfindViewById。 btwどこにフォントファイルを置いたのですか? – user5599807