Java 未为参数类型字符串int定义运算符*
问题: 我试图通过SharedReferences提取布尔值,但是每次尝试使用该值时,我都会收到一个编译器错误,说明参数类型的运算符未定义。我不确定为什么会发生这种情况-我相信我已经将时间布尔值转换为字符串-然后我应该能够使用它作为一个值乘以以获得我的时间值: 资料来源:Java 未为参数类型字符串int定义运算符*,java,operators,Java,Operators,问题: 我试图通过SharedReferences提取布尔值,但是每次尝试使用该值时,我都会收到一个编译器错误,说明参数类型的运算符未定义。我不确定为什么会发生这种情况-我相信我已经将时间布尔值转换为字符串-然后我应该能够使用它作为一个值乘以以获得我的时间值: 资料来源: String PREF = "prefs"; SharedPreferences prefs = getSharedPreferences(PREF, Context.MODE_PRIVATE); b
String PREF = "prefs";
SharedPreferences prefs = getSharedPreferences(PREF, Context.MODE_PRIVATE);
boolean name = prefs.getBoolean("name", true);
boolean code = prefs.getBoolean("corename", true);
boolean time = prefs.getBoolean("time", true);
boolean ssid = prefs.getBoolean("restricted", true);
String killtime = String.valueOf(time);
Intent intent2 = new Intent(Rules.this, KillTimer.class);
PendingIntent pintent2 = PendingIntent.getActivity(Rules.this, 0, intent2,
0);
AlarmManager alarm2 = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
killtime * 1000, pintent2); // error is thrown here
您正试图将
字符串
和整数
相乘。那没有道理。然后,如果将字符串
强制为int
的话,它的值就没有意义了-它要么是1要么是0,这可以用三元语句更清楚地说明(足够有趣)
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
time ? 1000 : 0, pintent2);
你在哪一行出错