我正在尝试使用SharedPreferences并且偶然发现了我的一个可能很愚蠢的错误。这是我的代码(MainActivity类):
private Boolean checkSSID;
private String connectionSSID;
private int leftPort;
private int rightPort;
private int LLUPort;
private int localUDPPort;
private String platformIPAddrStr;
在onCreate()方法的底部:
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
SharedPreferences sharedPref =
PreferenceManager.getDefaultSharedPreferences(this);
checkSSID = sharedPref.getBoolean
(SettingsActivity.KEY_PREF_CHECK_SSID, false);
connectionSSID = sharedPref.getString
(SettingsActivity.KEY_PREF_CONNECTION_SSID, "\"bulldog\"");
leftPort = sharedPref.getInt
(SettingsActivity.KEY_PREF_LEFT_UDP_PORT, 4001);
rightPort = sharedPref.getInt
(SettingsActivity.KEY_PREF_RIGHT_UDP_PORT, 4002);
LLUPort = sharedPref.getInt
(SettingsActivity.KEY_PREF_LLU_UDP_PORT, 8888);
localUDPPort = sharedPref.getInt
(SettingsActivity.KEY_PREF_LOCAL_UDP_PORT, 5555);
platformType = sharedPref.getInt
(SettingsActivity.KEY_PREF_PLATFORM_TYPE,0);
在第一次getInt()调用应用程序崩溃时出现此错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.xxx/it.xxx.MainActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
ibeautiful
梵蒂冈之花
慕标5832272
相关分类