2016-06-11 3 views
0

Android Studio 및 SDK를 업데이트 한 후 에뮬레이터 또는 장치에서 내 앱을 실행할 수 없습니다. 항상 같은 오류가 발생합니다 invalid float.활동을 시작할 수 없습니다 : 부울 값이 잘못됨

MySettingsActivity.java :

public class MySettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); 

     setContentView(R.layout.preference_screen); 
     addPreferencesFromResource(R.xml.preferences); 

     getListView().addHeaderView(LayoutInflater.from(this).inflate(R.layout.preference_header, null)); 
     getListView().setSelector(getResources().getDrawable(R.drawable.listview_item_background)); 
     getListView().setVerticalFadingEdgeEnabled(false); 
     getListView().setOverScrollMode(ListView.OVER_SCROLL_NEVER); 
    } 

    @Override 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) 
    { 
     if (key.equals("touch_reaction")) 
     { 
      boolean touch_reaction = sharedPreferences.getBoolean("touch_reaction", true); 
      toast("Touch Reaction: ", touch_reaction ? "ON" : "OFF"); 
      return; 
     } 
    } 

    private void toast(String text, String more) 
    { 
     View layout = getLayoutInflater().inflate(R.layout.toast, null); 

     TextView text_view = (TextView) layout.findViewById(R.id.text); 
     text_view.setText(text); 

     TextView more_view = (TextView) layout.findViewById(R.id.more); 
     more_view.setText(more); 

     if (more.equals("")) 
     { 
      ((ViewManager) more_view.getParent()).removeView(more_view); 
     } 

     Toast toast = new Toast(getApplicationContext()); 
     toast.setDuration(Toast.LENGTH_SHORT); 
     toast.setView(layout); 
     toast.show(); 
    } 

    private void toast(String text) 
    { 
     toast(text, ""); 
    } 
} 

로그 캣 :

당신의 loadPersistedColor() -method에서
--------- beginning of crash 
06-11 22:27:48.017 6196-6196/starbox.connect E/AndroidRuntime: FATAL EXCEPTION: main 
Process: starbox.connect, PID: 6196 
java.lang.RuntimeException: Unable to start activity ComponentInfo{starbox.connect/starbox.connect.MySettingsActivity}: 
    java.lang.NumberFormatException: Invalid float: "" 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.NumberFormatException: Invalid float: "" 
at java.lang.StringToReal.invalidReal(StringToReal.java:63) 
at java.lang.StringToReal.parseFloat(StringToReal.java:308) 
at java.lang.Float.parseFloat(Float.java:306) 
at starbox.connect.MyColorPreference.loadPersistedColor(MyColorPreference.java:185) 
at starbox.connect.MyColorPreference.onSetInitialValue(MyColorPreference.java:127) 
at android.preference.Preference.dispatchSetInitialValue(Preference.java:1385) 
at android.preference.Preference.onAttachedToHierarchy(Preference.java:1182) 
at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:164) 
at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:105) 
at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:104) 
at android.preference.GenericInflater.rInflate(GenericInflater.java:490) 
at android.preference.GenericInflater.rInflate(GenericInflater.java:495) 
at android.preference.GenericInflater.inflate(GenericInflater.java:327) 
at android.preference.GenericInflater.inflate(GenericInflater.java:264) 
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:273) 
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1521) 
at starbox.connect.MySettingsActivity.onCreate(MySettingsActivity.java:27) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+1

'starbox.connect.MyColorPreference'는 특히'loadPersistedColor()'메소드에서 불만입니다. – CommonsWare

답변

2

하는 Float.parseFloat(String) 울어은이 있어야 할 곳에 당신이에 전달하는 문자열 함수는 빈 문자열 ("")입니다. 이는 유효한 부동 소수점 값이 아닙니다.

질문 : 그게 유효한 상황입니까? 문자열이 비어있는 경우 (논리에서) 괜찮 으면 빈 문자열을 확인하고 기본값을 반환하십시오. 논리에 유효하지 않은 경우 데이터를 저장하는 데 문제가있을 수 있습니다.