android - Probleme of Preferences in class extends Fragment -


sharedpreferences prefs1 = getsharedpreferences("monfichierdeprefs",mode_private); 

the same syntax works on class extend activity not in extends fragment added context syntax error has disappeared when press button "demande" application stops error come preferance sure may not find solution me please!!!!!

public class pagegauchefragment extends fragment {   private static string key_success = "success";  private static string key_error = "error";  final string para_nom = "parametre2";  final string para_nom1 = "parametre3";  context context;  public string fname,lname,ftype;  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     view view = inflater.inflate(r.layout.page_gauche, container, false);   /**  * action sur bouton demande  * **/         button button = (button) view.findviewbyid(r.id.button1);     button.setonclicklistener(new view.onclicklistener() {       @override       public void onclick(view v) {         sharedpreferences  prefs1 = context.getsharedpreferences("monfichierdeprefs",context.mode_private);         fname = prefs1.getstring(para_nom, "");              lname = prefs1.getstring(para_nom1, "");             ftype="salut";            //apelle de la fonction netasync qui verifie la connextion et envoie de demande            netasync(v);                   }     });      return view; } 

try this..

change this..

sharedpreferences  prefs1 = context.getsharedpreferences("monfichierdeprefs",context.mode_private); 

to

sharedpreferences  prefs1 = getactivity().getsharedpreferences("monfichierdeprefs",context.mode_private); 

or

context = getactivity(); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -