In my Android project, I have Service:
public class MyService extends Service{
public MyService(){
File dir = getDir("my_dir", Context.MODE_PRIVATE);
}
@Override
public void onCreate(){
super.onCreate();
...
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
...
}
}
I know fine, I should not explicitly define the constructor for Android Service. But in my case, I want to use the constructor to create a directory in my internal storage.
When I try, I got a NullPointerException that I don’t understand why? Can someone explain to me the reason I got a NullPoineterException when called getDir(...)in my explicite constructor?
source
share