Question

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();
Was it helpful?

Solution

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

OTHER TIPS

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();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top