Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未为参数类型字符串int定义运算符*_Java_Operators - Fatal编程技术网

Java 未为参数类型字符串int定义运算符*

Java 未为参数类型字符串int定义运算符*,java,operators,Java,Operators,问题: 我试图通过SharedReferences提取布尔值,但是每次尝试使用该值时,我都会收到一个编译器错误,说明参数类型的运算符未定义。我不确定为什么会发生这种情况-我相信我已经将时间布尔值转换为字符串-然后我应该能够使用它作为一个值乘以以获得我的时间值: 资料来源: String PREF = "prefs"; SharedPreferences prefs = getSharedPreferences(PREF, Context.MODE_PRIVATE); b

问题:

我试图通过SharedReferences提取布尔值,但是每次尝试使用该值时,我都会收到一个编译器错误,说明参数类型的运算符未定义。我不确定为什么会发生这种情况-我相信我已经将时间布尔值转换为字符串-然后我应该能够使用它作为一个值乘以以获得我的时间值:

资料来源:

    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);

你在哪一行出错