I've got a problem using sharedpreferences in my toggle button. First, i declared what i need:

```
public SharedPreferences preferences;
public WifiManager wifiManager;
ToggleButton wifitoggle;

```

Then the "action" onClikc

```
// toggle wifi
    public void wifi (View view) {
        wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        boolean wifion = ((ToggleButton) view).isChecked();
        if (wifion) {
            wifiManager.setWifiEnabled(true);
            // Shared preferences
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("togglewifi", true); // value to store
            editor.commit();

        }else{
            wifiManager.setWifiEnabled(false);
            // Shared preferences
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("togglewifi", false); // value to store
            editor.commit();

        }
    }

```

and in my onCreate i reported the value:

```
boolean togglewifi = preferences.getBoolean("togglewifi", false);  //default è false
        if (togglewifi) 
        {

            wifitoggle.setChecked(true);
        }
            else
        {
            wifitoggle.setChecked(false);
        }

```

But when i run the application it crashes. The strange thing is that the logCat say nothing. No errors.. Have i missed something? Thanks for help