Android: NullPointerException Working With SharedPreferences

前端 未结 3 2027
北恋
北恋 2021-01-23 21:12

Working with SharedPreferences, this activity crashes upon launching. First I\'ll post the activity code, and then I\'ll post my LogCat. Thank you so much guys, you guys are alw

3条回答
  •  无人及你
    2021-01-23 21:19

    public class MainActivity extends Activity{
    
    SharedPreferences sharedpreferences;    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
    sharedpreferences = getSharedPreferences("preferences", Context.MODE_PRIVATE);  
    
                editor.putBoolean("sharedpreferences", true);
                editor.commit();
    
    // your code ...
    
    }
    
    // your code ...
    }
    

提交回复
热议问题