Home > Mobile >  Why can't, genuflect is begged openFileOutput () function call
Why can't, genuflect is begged openFileOutput () function call

Time:04-08

Post for the first time, 50 points to the great god see, why can't this function call, the application permissions are applied for, change of import should be imported, why not call ahhh? !!!!! ?
 private void the output () {

The String content=TvTagUii. GetText (). The toString ();
FileOutputStream fos;

Try {
Fos=openFileOutput (" data. TXT ", MODE_PRIVATE);
Fos. Write (content. getBytes ());
fos.close();
/* PrintStream ps=new PrintStream (fos);
Ps. Println (content);
Ps. The close ();
fos.close(); */

} the catch (Exception e) {
e.printStackTrace();
}


}

CodePudding user response:

 enclosing openFileOutput (" data. TXT ", MODE_PRIVATE); 


This here need a Context instances such as Activity, you this output () method is to write in a certain Activity? If not, then you need a Context instance and then points out the openFileOutput method

CodePudding user response:

reference 1st floor xj396282771 response:
 enclosing openFileOutput (" data. TXT ", MODE_PRIVATE); 


This here need a Context instances such as Activity, you this output () method is to write in a certain Activity? If not, then you need a Context instance and then points out the openFileOutput method

But after I have instantiation, causing collapse program is running, a great god knows what reason?

CodePudding user response:

You stick this method in class class I see, and indicate where you instantiate an error

CodePudding user response:

reference xj396282771 reply: 3/f
you stick the method in class class I see, and indicate where you instantiate an error

The output () by a button listener calls,
 public class BtClearClickListener implements an OnClickListener {
@ Override
Public void onClick (View v) {output (); }}

Then call the button definition here
 @ override 
Public void onActivityCreated (Bundle savedInstanceState) {
BtClear. SetOnClickListener (new BtClearClickListener ()); }

Then buttons and text view defined in the derived class
 public class UHFReadTagFragment extends KeyDwonFragment 

KeydownFragment inherited fragments
This collapse is a runtime error displayed in the output (where)

CodePudding user response:

That is to say, your output () method to write on your UHFReadTagFragment class,
Then you should call the getActivity (). OpenFileOutput (" data. TXT ", MODE_PRIVATE);
In addition I saw you here hint null pointer exception, then there is another possibility is "data. TXT" the path to the file does not exist here, you need to test your file exists, or the path is correct

CodePudding user response:

1, read the newspaper a null pointer exception is 370 lines, 370 according to your post code is not it? The String content=TvTagUii. GetText (). The toString (); - & gt; Please confirm whether the object is null or the object's getText null.

2, your fos=openFileOutput (" data. TXT ", MODE_PRIVATE); Suggest that the following
Private static final String sTempCropFilename="crop - temp";

The File path=mActivity. GetFileStreamPath (sTempCropFilename);
Path. The delete ();
TempStream=mActivity. OpenFileOutput (sTempCropFilename, MODE_PRIVATE);

CodePudding user response:

The private void the output () {} wrote the class MainActivity: AppCompatActivity () {} there was no problem
  • Related