Attempt to read from field 'long android.graphics.Typeface.native_instance' on a null object reference

439 Views Asked by At

Hi My application crashes on Motorola g stylus, here is the crash log

Logs are here

android.graphics.Typeface.setDefault (Typeface.java:199)
    android.graphics.Typeface.init (Typeface.java:1207)
    android.graphics.Typeface.updateThemeFont (Typeface.java:1262)
    android.app.ActivityThread.handleBindApplication (ActivityThread.java:6894)
    android.app.ActivityThread.access$1500 (ActivityThread.java:252)
    android.app.ActivityThread$H.handleMessage (ActivityThread.java:1999)
    android.os.Handler.dispatchMessage (Handler.java:106)
    android.os.Looper.loop (Looper.java:250)
    android.app.ActivityThread.main (ActivityThread.java:7877)
    java.lang.reflect.Method.invoke (Method.java)
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
    com.android.internal.os.ZygoteInit.main (ZygoteInit.java:958)

Please check what went wrong

1

There are 1 best solutions below

0
Vishal Naikawadi On

In my case, the crash was happening on the Motorola edge 30. The issue was end-user changed the font style from the settings. The quick fix was to change it back to the default one (check the screenshots).

From the code point of view, the below code block was causing the issue.

final Typeface customFontTypeface = Typeface.createFromAsset(context.getAssets(), customFontFileNameInAssets);

Typeface.createFromAsset is the real culprit here. but the same code worked on other devices.

It was not adding major value to my code so I just removed it. and it worked fine. If anyone find a solution please do comment.