Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Application Crashes if System Font Size is changed

If I put my application in the background by clicking home.

Then Go to System Settings -> Display -> Font Size -> And change from (Normal) to (Huge)

Then Go click on my applicaiton to put it back in the foreground

I get the following error message:

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity{ActivityThread.java)

Does anyone know what might be causing this error?

Here's the entire Logcat pertaining to that error:

    08-01 14:16:44.555: E/AndroidRuntime(3979): FATAL EXCEPTION: main
    08-01 14:16:44.555: E/AndroidRuntime(3979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivity}: java.lang.NullPointerException
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.access$800(ActivityThread.java:140)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.os.Looper.loop(Looper.java:137)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.main(ActivityThread.java:4921)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at java.lang.reflect.Method.invoke(Method.java:511)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at dalvik.system.NativeStart.main(Native Method)
    08-01 14:16:44.555: E/AndroidRuntime(3979): Caused by: java.lang.NullPointerException
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.Menu.ResetMenuPosition(Menu.java:2328)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.Menu.onActivityCreated(Menu.java:573)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.MainActivity.onStart(MainActivity.java:299)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.Activity.performStart(Activity.java:5198)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     ... 12 more
like image 409
Eric Bergman Avatar asked Aug 01 '13 18:08

Eric Bergman


1 Answers

In Xamarin add these line of code on the top of your activity.

[Activity(ConfigurationChanges =ConfigChanges.FontScale)]
public class ExampleActivity : AppCompatActivity { rest of the code ... }
like image 111
Biswajit Panday Avatar answered Nov 15 '22 01:11

Biswajit Panday