Android 用户首选项错误

Android User Preferences Error

我从下面的代码中收到以下错误。它似乎 运行 在虚拟设备上很愉快,但我 运行 它在真实设备上很快就崩溃了。

Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:223)

这是似乎抛出错误的函数的代码。

 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") {

您可能正在向 sharedpreference 添加一个整数并尝试将其作为字符串获取。尝试以这种方式添加字符串 "status"。

Editor editor = sharedpreferences.edit();
editor.putString("status",string.valueof(YOUR STATUS INTEGR));
editor.commit();