If i have my class as
import java.io.File;
import java.io.FileOutputStream;
//Extends Activity
public class MyClass extends Activity
{
File fileDir = getFilesDir(); //no error
. ....
}
But if i don't extend MyClass , i get an error saying "getFilesDir()" undefined.
some thing like
public class MyClass2
{
....
File fileDir = getFilesDir(); 开发者_运维问答//error
}
That is the method of the Context class. You have to obtain an instance of the class to invoke it.
http://developer.android.com/reference/android/content/ContextWrapper.html#getFilesDir()
getFilesDir is member of ContextWrapper. So if you don't extend ContextWrapper it's normal for the compiler to throw error undefined reference.
精彩评论