I have put this section of code in my Setting Activity, so if the vibration box in the xml file which is working is checked, vibrators will be turned on and if not they will be cancelled. However, there seems to be a problem with the else that won't let me run the app. Any help would be appreciated, thanks.

  if (preference instanceof vibrateapp_checkbox=="true");
    Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
    Else if (preference instanceof vibrateapp_checkbox=="false");
    Vibrator.cancel();
有帮助吗?

解决方案

its not Else its else. java is case sensitive. moreover, the else is without if because you ended if by (;)

if (preference instanceof vibrateapp_checkbox=="true")
    Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
else if (preference instanceof vibrateapp_checkbox=="false")
    Vibrator.cancel();

moreover, this seems incorrect (preference instanceof vibrateapp_checkbox=="false") since after instanceof, type is expected not value

you can correct it as

if (vibrateapp_checkbox.isChecked())
        Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
    else
        Vibrator.cancel();

其他提示

Java is Case sensitive . Use else not Else

  if (preference instanceof vibrateapp_checkbox=="true")
    {
        Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
    }
        else if (preference instanceof vibrateapp_checkbox=="false")
    {
        Vibrator.cancel();
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top