Custom Fonts in Android: java.lang.RuntimeException

Eddev

I am trying to use a custom font within a TextView of an Android Studio application, but am getting the following error:

enter image description here

It's a null pointer exception; in the below code, txt is null for some reason:

Java:

    TextView txt;

    txt.setText("A");


    txt = (TextView) findViewById(R.id.custom_font);
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Grundschrift.ttf");
    txt.setTypeface(font);

XML:

android:id="@+id/custom_font"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="A"

Thanks!

Inducesmile

With this part of your,

TextView txt;
txt.setText("A");

implies that you are calling a method setText() in a null object. To use this method, you have to first initialize the TextView.

so change this

TextView txt;
txt.setText("A");

txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Grundschrift.ttf");
txt.setTypeface(font);

to

TextView txt; 
txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Grundschrift.ttf");
txt.setTypeface(font);
txt.setText("A");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android custom-view - java.lang.RuntimeException android.view.InflateException

From Dev

Android [LocationManager] requestLocationUpdates(), java.lang.RuntimeException

From Dev

Android app java.lang.RuntimeException error

From Dev

Android PreferenceFragment : java.lang.RuntimeException

From Dev

java.lang.RuntimeException: Android Runtime error

From Dev

Android Boilepipe - java.lang.RuntimeException

From Dev

Android RuntimeException caused by java.lang.ClassNotFoundException

From Dev

Android JSON: java.lang.RuntimeException: Unable to start activity ComponentInfo

From Dev

Android "java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object"

From Dev

Android Media Recording: java.lang.RuntimeException: start failed

From Dev

android java lang runtimeexception fail to connect to camera service

From Dev

java.lang.RuntimeException: Unable to start activity ComponentInfo Android Manifest

From Dev

Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed

From Dev

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - Android

From Dev

java.lang.RuntimeException: Performing stop of activity that is not resumed in android

From Dev

Android java.lang.RuntimeException: Error receiving broadcast Intent

From Dev

Android+Robolectric Test ERROR "java.lang.RuntimeException: Stub!"

From Dev

RuntimeException: Unable to start activity ComponentInfo{}: java.lang.NullPointerException. Android

From Dev

Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed

From Dev

Java.lang.RuntimeException: Unable to start activity ComponentInfo Error in Android

From Dev

java.lang.RuntimeException: Unable to start activity ComponentInfo in android

From Dev

java.lang.RuntimeException,Caused by: android.view.InflateException

From Dev

java.lang.RuntimeException:IllegalAccessException

From Dev

Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo ... java.lang.NullPointerException

From Dev

java.lang.runtimeexception unable to start activity componentinfo java.lang.nullpointerexception android

From Dev

Android Studio 1.0.2: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException

From Dev

Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo ... java.lang.NullPointerException

From Dev

Android java runnable runTimeException

From Dev

Android java runnable runTimeException

Related Related

  1. 1

    Android custom-view - java.lang.RuntimeException android.view.InflateException

  2. 2

    Android [LocationManager] requestLocationUpdates(), java.lang.RuntimeException

  3. 3

    Android app java.lang.RuntimeException error

  4. 4

    Android PreferenceFragment : java.lang.RuntimeException

  5. 5

    java.lang.RuntimeException: Android Runtime error

  6. 6

    Android Boilepipe - java.lang.RuntimeException

  7. 7

    Android RuntimeException caused by java.lang.ClassNotFoundException

  8. 8

    Android JSON: java.lang.RuntimeException: Unable to start activity ComponentInfo

  9. 9

    Android "java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object"

  10. 10

    Android Media Recording: java.lang.RuntimeException: start failed

  11. 11

    android java lang runtimeexception fail to connect to camera service

  12. 12

    java.lang.RuntimeException: Unable to start activity ComponentInfo Android Manifest

  13. 13

    Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed

  14. 14

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - Android

  15. 15

    java.lang.RuntimeException: Performing stop of activity that is not resumed in android

  16. 16

    Android java.lang.RuntimeException: Error receiving broadcast Intent

  17. 17

    Android+Robolectric Test ERROR "java.lang.RuntimeException: Stub!"

  18. 18

    RuntimeException: Unable to start activity ComponentInfo{}: java.lang.NullPointerException. Android

  19. 19

    Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed

  20. 20

    Java.lang.RuntimeException: Unable to start activity ComponentInfo Error in Android

  21. 21

    java.lang.RuntimeException: Unable to start activity ComponentInfo in android

  22. 22

    java.lang.RuntimeException,Caused by: android.view.InflateException

  23. 23

    java.lang.RuntimeException:IllegalAccessException

  24. 24

    Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo ... java.lang.NullPointerException

  25. 25

    java.lang.runtimeexception unable to start activity componentinfo java.lang.nullpointerexception android

  26. 26

    Android Studio 1.0.2: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException

  27. 27

    Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo ... java.lang.NullPointerException

  28. 28

    Android java runnable runTimeException

  29. 29

    Android java runnable runTimeException

HotTag

Archive