[英]Android User Preferences Error
I am getting the following error thrown from the code below. 我从下面的代码中引发以下错误。 It seems to run happily on a virtual device but as soon at I run it on a real device it crashes. 它似乎可以在虚拟设备上愉快地运行,但是一旦我在真实设备上运行它,它就会崩溃。
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:223) 造成原因:java.lang.ClassCastException:无法将android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:223)上的java.lang.Integer强制转换为java.lang.String。
Here is the code of the function that seems to throw the error. 这是似乎引发错误的函数代码。
public void queueJump2() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("settings");
query.getInBackground("BauCSafDjA", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
String queueJumpActive = object.getString("status");
Log.i("QUEUE JUMP STATUS >>",queueJumpActive);
if (!queueJumpActive.equals("active")){
Button qjumpButton = (Button)findViewById(R.id.qjumpButton);
qjumpButton.setText("DISABLED");
} else {
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
Long dayAgoLong = (System.currentTimeMillis()/1000)-84600;
String dayAgo = dayAgoLong.toString();
Log.i("Current Time Stamp: ", ts.toString());
Log.i("dayAgo >>: ", dayAgo.toString());
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("HH");
TimeZone tz = TimeZone.getTimeZone("EST");
boolean inDs = tz.inDaylightTime(new Date());
if (String.valueOf(inDs) == "false") {
You might be adding an integer to sharedpreference and trying to get it as a string. 您可能要在sharedpreference中添加一个整数,然后尝试将其作为字符串获取。 Try adding your string "status" this way. 尝试以这种方式添加字符串“状态”。
Editor editor = sharedpreferences.edit();
editor.putString("status",string.valueof(YOUR STATUS INTEGR));
editor.commit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.