gpt4 book ai didi

android - 错误 :non static method 'edit' cannot be referenced in static context

转载 作者:搜寻专家 更新时间:2023-11-01 07:52:54 25 4
gpt4 key购买 nike

public class NavigationDrawerFragment extends Fragment {

public static final String PREF_FILE_NAME="testpref";
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLyout;

private boolean mUserLearnedDrawer;
private boolean mFromSavedInstanceState;
public NavigationDrawerFragment() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
}


public void setUp(DrawerLayout drawerLayout,Toolbar toolbar) {
mDrawerLyout=drawerLayout;
mDrawerToggle=new ActionBarDrawerToggle(getActivity(),drawerLayout,toolbar,R.string.drawer_open,R.string.drawer_close){

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
mDrawerLyout.setDrawerListener(mDrawerToggle);

}
public void saveToPreferences(Context context, String preferenceName, String preferenceValue)
{
SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor=SharedPreferences.edit();
editor.putString(preferenceName, preferenceValue);
editor.commit();
}

所以我在线上有错误,SharedPreferences.Editor editor=SharedPreferences.edit();

Error:non static method 'edit' cannot be referenced in static context

最佳答案

尝试

SharedPreferences.Editor editor=sharedPreferences.edit();

代替

SharedPreferences.Editor editor=SharedPreferences.edit();

你不能直接SharedPreferences.edit(); .

您必须创建 SharedPreferences 的对象你已经创建了sharedPreferences所以用它来调用edit()方法。

希望对您有所帮助!

关于android - 错误 :non static method 'edit' cannot be referenced in static context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com