我现在得到这个logcat !! 每当我有这个消息并强行关闭!! 之前我问过这个问题,但是我收到了一个新错误! exu!
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{yaAli.package313.hossein110/yaAli.package313.hossein110.know}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:301)
at java.lang.Float.parseFloat(Float.java:291)
at java.lang.Float.valueOf(Float.java:330)
at yaAli.package313.hossein110.know.onCreate(know.java:67)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
我在回答你的答案后得到了新的logcat:
FATAL EXCEPTION: main
java.lang.NumberFormatException: unable to parse '' as integer
at java.lang.Integer.parseInt(Integer.java:412)
at java.lang.Integer.parseInt(Integer.java:382)
at java.lang.Integer.valueOf(Integer.java:682)
at yaAli.package313.hossein110.know$1.run(know.java:37)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:4)
从你的代码:
String sizefa = sharedpreferences.getString("fontsizefa",null);
...
tvfa.setTextSize(1, Float.valueOf(sizefa).floatValue());
如果您的首选项不包含“fontsizefa”,则将其设置为null。抛出异常是因为稍后您尝试将空字符串转换为浮点数。
将其更改为:
String sizefa = sharedpreferences.getString("fontsizefa","0.0");
或任何您想要的默认大小。
当colorfa
不符合您的偏好时,您也会遇到同样的问题。