简体   繁体   中英

extends Java class

I'm trying to use the GPUImage android class. I have already built an android app around this but I need to add some additional feature to the GPUImage class.

To do so I have done :

public class GPUImageExt extends GPUImage {
}

I need to override some of them but I also have to add some new methods.

For example a SavedListener exists and I need to add an additional listener.

Unfortunately, I got an issue saying :

There is no default constructor available in co.jp.cyberagent.android.gpuimage.GPUImage

How do I fix this ?

You would have to decide which existing constructors of GPUImage to call from the constructors of your sub-class.

For example, since GPUImage has a constructor that takes a single parameter of type Context , you can have in your sub-class a constructor :

public GPUImageExt (Context context)
{
    super (context);
    ...
}

or :

public GPUImageExt (Context context, SomeOtherType someOtherParam)
{
    super (context);
    ...
}

You can see the source here

Try this

public GPUImageExt( final Context context )
{
    super( context );
}

Your constructors must call the declared constructors of GPUImage

public GPUImage(final Context context)

You may want to consider if you want to be subclassing GPUImage at all, rather than wrapping it in something and using composition/delegation.

A default constructor, is a constructor that takes no arguments, so just add one to your class, even if you won't use it.

public class GPUImageExt extends GPUImage {
Context context;

public GPUImageExt (Context context)
{
super (context);
this.context = context;
...
}
//default constructor
GPUImageExt(){
super(context);
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM