I’m trying to call a method, WriteToFile, from The main method. Here is what I have so far:
public void main(String [ ] args)
{
String fileLoc = Environment.getExternalStorageDirectory() + File.separator + "AccelData.txt";
File AccelData = new File(fileLoc);
AccelData.WriteToFile(fileLoc, AccelData);
}
And the WriteToFile method is:
public void WriteToFile(String fileLoc, File AccelData){
//code in here
}
I get a red line under the AccelData.WriteToFileline, which just says I should add a cast, which doesn’t fix it.
Thanks for your help.
You cannot apply
WriteToFile()method tojava.io.Fileinstances, becuase it’s not defined in standard Java File class.One alternative way you can apply to your code is declaring your method as static:
And in the main method just call it with its name:
Second way could be creating an instance of the class which encapsulates
WriteToFile()method, and then invoking that method on your instance again in main method: