android - Cannot resolve method 'openFileOutput(java.lang.String,int) -


a night before, implemented code snippet in android studio access file , write string in file.but how not able build sucessfully. don't know wrong "openfileoutput()" method. have tried adding context before openfileoutput() method, doesn't work , if not wrong must not.

please me. here code part implementing snippet.

package com.medaino.www.twitterapp;  import android.app.listactivity; import android.content.context; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.widget.listview;  import java.io.fileoutputstream; import java.io.objectoutputstream; import java.lang.string; import java.util.arraylist; import java.util.list;   import android.view.view; import android.content.intent;   public class tweetlistactivity extends listactivity {    // private listview tweetlistview;     private string[] stringarray ;     private tweetaapter tweetitemarrayadapter;        public list<tweet> getdataforlistview()     {         list<tweet> tweets = new arraylist<tweet>();         ( int = 0; < 10; i++ )         {             tweet twt = new tweet();             twt.settitle("a nice header tweet # " +i);             twt.setbody("some random body text tweet # " +i);             tweets.add(twt);          }          string filename = "hello_file";         string string = "hello world!";          fileoutputstream fos = context.openfileoutput(filename,mode_private);         fos.write(string.getbytes());         fos.close();          return tweets;     }          @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_tweetlistactivity);         stringarray = new string[10];         list<tweet> tweetlist = getdataforlistview() ;         tweetitemarrayadapter = new tweetaapter(this, stringarray, tweetlist);         setlistadapter(tweetitemarrayadapter);      }     @override     protected void onlistitemclick(listview list, view v, int position, long id)     {         intent intent = new intent(this, tweet_detail.class);         startactivity(intent);     }      @override     public boolean oncreateoptionsmenu(menu menu)     {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_tweetlistactivity, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     }   } 

openfileoutput(); needs context. calling in arrayadapter. should be:

// define context use below code context.openfileoutput(); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -