Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在androidStudio中声明新的空对象_Java_Object_Android Studio - Fatal编程技术网

Java 如何在androidStudio中声明新的空对象

Java 如何在androidStudio中声明新的空对象,java,object,android-studio,Java,Object,Android Studio,我创建了一个类并将其命名为“PaymentObject” 在我的mainactivity类中,我想初始化PaymentObject类型的新空对象 然后设置对象的值。 像这样: PaymentObject po = new PaymentObject(); po.setPrecentsValue(1); po.setPrecentsText("100%"); 但当我这样做时,会出现一个错误“PaymentObject中的PaymentObject(string,double)不能

我创建了一个类并将其命名为“PaymentObject”

在我的mainactivity类中,我想初始化PaymentObject类型的新对象 然后设置对象的值。 像这样:

PaymentObject po = new PaymentObject();
    po.setPrecentsValue(1);
    po.setPrecentsText("100%");
但当我这样做时,会出现一个错误“PaymentObject中的PaymentObject(string,double)不能应用于()” (仅当我在新对象上声明时添加值时,THA才起作用) 但是我想打开一个空的对象,然后设置值。。。 我该怎么办?
谢谢

要创建空对象,只需创建默认构造函数:

public PaymentObject(){}

如果不声明默认构造函数(无参数),就像禁止创建空对象一样。

要创建空对象,只需创建默认构造函数:

public PaymentObject(){}

如果不声明默认构造函数(无参数),就像禁止创建空对象一样。

要创建空对象,只需创建默认构造函数:

public PaymentObject(){}

如果不声明默认构造函数(无参数),就像禁止创建空对象一样。

要创建空对象,只需创建默认构造函数:

public PaymentObject(){}

当您不声明默认构造函数(没有参数)时,就像您禁止创建空对象一样。

您没有一个没有参数的构造函数。您必须为此创建一个

public PaymentObject(){
    //initialize maybe with default values if any based on use case
} 

你可能想读书

您没有一个没有参数的构造函数。您必须为此创建一个

public PaymentObject(){
    //initialize maybe with default values if any based on use case
} 

你可能想读书

您没有一个没有参数的构造函数。您必须为此创建一个

public PaymentObject(){
    //initialize maybe with default values if any based on use case
} 

你可能想读书

您没有一个没有参数的构造函数。您必须为此创建一个

public PaymentObject(){
    //initialize maybe with default values if any based on use case
} 

你可能想读书

在列出的代码中,您修改了默认构造函数行为以接受两个参数

我建议,有两个构造函数,一个没有参数,一个有参数

这样,您可以在需要时创建一个空对象,或者创建一个具有初始化成员变量的对象

按如下方式修改代码:

public class PaymentObject implements Serializable {

        double precentsValue;
        String PrecentsText;

@Override
public String toString() {
    return PrecentsText;
}

public PaymentObject()
{

}

public PaymentObject(String paymenttext,double paymentvalue)
{
   this.PrecentsText=paymenttext;
   this.precentsValue=paymentvalue;

}

public String getPrecentsText(){return PrecentsText;}
public void setPrecentsText(String percents){this.PrecentsText=percents;}
public double getPrecentsValue(){return precentsValue;}
public void setPrecentsValue(double percentsvalue) {this.precentsValue=percentsvalue;}


} 

在列出的代码中,您修改了默认构造函数行为以接受两个参数

我建议,有两个构造函数,一个没有参数,一个有参数

这样,您可以在需要时创建一个空对象,或者创建一个具有初始化成员变量的对象

按如下方式修改代码:

public class PaymentObject implements Serializable {

        double precentsValue;
        String PrecentsText;

@Override
public String toString() {
    return PrecentsText;
}

public PaymentObject()
{

}

public PaymentObject(String paymenttext,double paymentvalue)
{
   this.PrecentsText=paymenttext;
   this.precentsValue=paymentvalue;

}

public String getPrecentsText(){return PrecentsText;}
public void setPrecentsText(String percents){this.PrecentsText=percents;}
public double getPrecentsValue(){return precentsValue;}
public void setPrecentsValue(double percentsvalue) {this.precentsValue=percentsvalue;}


} 

在列出的代码中,您修改了默认构造函数行为以接受两个参数

我建议,有两个构造函数,一个没有参数,一个有参数

这样,您可以在需要时创建一个空对象,或者创建一个具有初始化成员变量的对象

按如下方式修改代码:

public class PaymentObject implements Serializable {

        double precentsValue;
        String PrecentsText;

@Override
public String toString() {
    return PrecentsText;
}

public PaymentObject()
{

}

public PaymentObject(String paymenttext,double paymentvalue)
{
   this.PrecentsText=paymenttext;
   this.precentsValue=paymentvalue;

}

public String getPrecentsText(){return PrecentsText;}
public void setPrecentsText(String percents){this.PrecentsText=percents;}
public double getPrecentsValue(){return precentsValue;}
public void setPrecentsValue(double percentsvalue) {this.precentsValue=percentsvalue;}


} 

在列出的代码中,您修改了默认构造函数行为以接受两个参数

我建议,有两个构造函数,一个没有参数,一个有参数

这样,您可以在需要时创建一个空对象,或者创建一个具有初始化成员变量的对象

按如下方式修改代码:

public class PaymentObject implements Serializable {

        double precentsValue;
        String PrecentsText;

@Override
public String toString() {
    return PrecentsText;
}

public PaymentObject()
{

}

public PaymentObject(String paymenttext,double paymentvalue)
{
   this.PrecentsText=paymenttext;
   this.precentsValue=paymentvalue;

}

public String getPrecentsText(){return PrecentsText;}
public void setPrecentsText(String percents){this.PrecentsText=percents;}
public double getPrecentsValue(){return precentsValue;}
public void setPrecentsValue(double percentsvalue) {this.precentsValue=percentsvalue;}


}