Java错误,找不到feild user2303583
您好,我正在尝试使用我的代码来创建新的构造函数对象,我需要创建移动电话对象,我已经尝试命名构造函数字段来创建对象,但是错误出现在Java错误,找不到feild user2303583,java,Java,您好,我正在尝试使用我的代码来创建新的构造函数对象,我需要创建移动电话对象,我已经尝试命名构造函数字段来创建对象,但是错误出现在 public Mobile(String Mobilephonetype, String Mobilescreensize, String Mobilememorycardcapacity, String Mobilecameraresolution, String MobileGPS), at the bottom of the pa
public Mobile(String Mobilephonetype, String Mobilescreensize,
String Mobilememorycardcapacity, String Mobilecameraresolution,
String MobileGPS), at the bottom of the page
为什么我会犯这个错误
java error, cannot find symbol - variable samsung
更新我已经将一些顶级字段从private int改为string,但现在它说找不到符号类string,这是什么意思 代码:
这条线路似乎是公共移动电话的问题方法:
this.phonetype = Samsung;
由于您在class mymobile
的main方法中定义了Samsung
对象,该对象在class Mobile
中不可用
更新:我真诚地建议您开始使用像Eclipse这样的IDE,以便在编辑器中捕捉到这些类型的错误
最喜欢的不是这个声明:
// type of phone
private int phonetype;
你的意思是:
// type of phone
private String phonetype;
然后使用此任务:
this.phonetype = Mobilephonetype;
没有这样的变量
Samsung
。在这方面:
this.phonetype = Samsung;
似乎您可能有意以某种方式将
Mobilephonetype
分配给它,但正如下面的评论所示,这是一个int
问题似乎是this.phonetype=Samsung
,尝试将其更改为this.phonetype=Mobilephonetype
如果您的构造函数有问题,您应该使用传递给构造函数的参数。您可以根据需要更改这些参数,还可以将参数分配给相应的类变量
在main方法中,实例化一个名为Samsung的实例,如下所示
Mobile Samsung = new Mobile("Samsung", "3", "4", "8",
"GPS");
这是实例化实例的正确方法。当实例化实例时,您将参数传递给构造函数。所以您应该像这样在构造函数中正确地传递参数
public Mobile(String mobilePhoneType, int mobileScreenSize,
int mobileMemoryCardCapacity, int mobileCameraResolution,
String mobileGPS) {
this.phonetype = mobilePhoneType;
this.screensize = mobileScreenSize;
this.memorycardcapacity = mobileMemoryCardCapacity;
this.cameraresolution = mobileCameraResolution;
this.GPS = mobileGPS;
// you do not use this ones during instantiation,you can remove them if you do not need or assign them some default values
this.serviceprovider = newserviceprovider;
this.typeofcontract = 12;
this.checkcharge = checkcharge;
}
根据您的参数传递,您有不兼容的类型变量,您可以如下更改它们
private String phonetype;
private int screensize;
private int memorycardcapacity;
private int cameraresolution;
private String GPS;
私有实例字段“phonetype”、“serviceprovider”和“GPS”的类型应为“String”,而不是“String”。请不要使用以大写字母开头的名称命名方法。
找不到符号类字符串,这是什么意思??
确切说明了什么。没有类字符串
。也许你的意思是String
?Mobilephonetype
实际上是字符串参数。嗨,我刚刚尝试用Mobilephonetype替换它,它给出了以下错误消息:不兼容的类型phonetype
是int
变量嗨,我刚刚尝试用Mobilephonetype替换它,它给出了下面的错误消息:不兼容的typesUPDATE我已经将一些顶级字段从private int更改为string,但现在它说找不到符号类string,这意味着什么?嗨,我以前使用过Eclipse,但我的导师说我们必须使用Bluej编辑器来创建此工作。您也可以使用任何其他IDE。您是否尝试过我的建议来解决您的问题。您好,是的,我尝试过,但当我编译它时,它说找不到符号类字符串,我已上载编辑过的更新代码您应该删除Mobile Samsung=new Mobile(“Samsung”、“3”、“4”、“8”、“GPS”);除此之外,还应删除其他内容(字符串Mobilephonetype、字符串Mobilescreensize、字符串mobilemorycardcapacity、字符串Mobilecameraresolution、字符串MobileGPS){this.phonetype=Mobilephonetype;this.screensize=3;this.memorycardcapacity=4;this.cameraresolution=8;this.GPS=GPS;this.serviceprovider=newserviceprovider;this.typeofcontract=12;this.checkcharge=checkcharge;}好的,我已经删除了上面的内容,并进行了替换。我修改了代码,但仍然出现错误:找不到symbol-class string。另外,您没有声明newserviceprovider
变量,并尝试使用它
private String phonetype;
private int screensize;
private int memorycardcapacity;
private int cameraresolution;
private String GPS;