Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragments should be static such that they can be re-instantiated by the system, and anonymous classes are not static [ValidFragment]

Error:Error: Fragments should be static such that they can be re-instantiated by the system, and anonymous classes are not static [ValidFragment]

private boolean checkFreeSpace(String path, long size) {
    long freeSpace = StorageUtil.getAvailableSpaceInBytes(path);
    if (freeSpace <= size) {

right there is the probleme>>> new DialogFragment() {

like image 892
George Stefan Avatar asked Jan 29 '26 15:01

George Stefan


1 Answers

As the documentation says (Fragment Documentation):

Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().

So i guess you are Extending/Implementing a Fragment Class and Overloading a constructor with parameters.

You can fix it using the setArguments(Bundle) method explained above.

like image 150
Johan Duke Avatar answered Jan 31 '26 06:01

Johan Duke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!