简体   繁体   English

扩展Java类

[英]extends Java class

I'm trying to use the GPUImage android class. 我正在尝试使用GPUImage android类。 I have already built an android app around this but I need to add some additional feature to the GPUImage class. 我已经围绕此构建了一个android应用,但是我需要向GPUImage类添加一些其他功能。

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. 例如,存在SavedListener ,我需要添加一个附加的侦听器。

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. 您必须决定从子类的构造函数中调用哪些现有的GPUImage构造函数。

For example, since GPUImage has a constructor that takes a single parameter of type Context , you can have in your sub-class a constructor : 例如,由于GPUImage具有一个采用Context类型的单个参数的构造函数,因此您可以在子类中具有一个构造函数:

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 您的构造函数必须调用已声明的GPUImage构造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. 您可能要考虑是否要完全继承GPUImage,而不是将其包装在某种东西中并使用合成/委托。

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);
}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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