0
当我在我的主类中添加构造函数时,由于下面的代码,它会给出错误。我能知道为什么吗? (无构造函数,它工作正常。)向主类添加构造函数后的android-错误
public class AndroidGPSTrackingActivity extends Activity implements OnClickListener{
Button btnShowLocation ;
private final Context mContext;
public AndroidGPSTrackingActivity(Context context) {
this.mContext = context.getApplicationContext();
//tpMethod();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("Main", "class");
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
// show location button click event
btnShowLocation.setOnClickListener(this);
}
}
错误: 了java.lang.RuntimeException:无法实例活动ComponentInfo
java.lang.InstantiationException
发布整个logcat跟踪和相关代码。 – 2013-04-10 15:23:24
java.lang.instantiationexception无法实例化类没有空的构造函数 – stack 2013-04-10 16:16:14
为什么要向活动添加构造函数呢? – 2013-04-10 16:16:56