Java 错误:此类应提供默认构造函数
我试图生成签名的APK,但出现以下错误: 错误:错误:此类应提供默认构造函数(公共 构造函数(不带参数) (com.penta.games.mrpolitik.SpendenDialog)[可实例化] 这是我的对话框文件Java 错误:此类应提供默认构造函数,java,android,class,dialog,super,Java,Android,Class,Dialog,Super,我试图生成签名的APK,但出现以下错误: 错误:错误:此类应提供默认构造函数(公共 构造函数(不带参数) (com.penta.games.mrpolitik.SpendenDialog)[可实例化] 这是我的对话框文件 package com.penta.games.mrpolitik; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.n
package com.penta.games.mrpolitik;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class SpendenDialog extends Dialog implements
android.view.View.OnClickListener {
private Activity c;
private Button yes, no;
public SpendenDialog(Activity a) {
super(a);
this.c = a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.spenden_dialog);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
Uri uri = Uri.parse("https://patreon.com/user?u=5716519&utm_medium=social&utm_source=twitter&utm_campaign=creatorshare2");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
c.startActivity(intent);
break;
}
switch (v.getId()) {
case R.id.btn_no:
break;
}
dismiss();
}
}
如何解决此错误
如何解决此错误
步骤#1:删除构造函数
步骤2:删除c
字段
第三步:将以前对
c
的所有引用替换为getContext()
清单中的某处是否列出了SpendenDialog
?顺便说一句,错误消息是误导性的。默认构造函数不仅仅是任何旧的“没有参数的公共构造函数”,当没有为类定义构造函数时,它是编译器提供的构造函数。