Java 错误,找不到符号 - 类字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19471477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java error, cannot find symbol - class string
提问by user2898828
I am trying to get my code to create the new constructor objects which I require to create a mobile phone object. I have tried naming the constuctor fields to create the object.
我试图让我的代码创建新的构造函数对象,我需要创建一个移动电话对象。我尝试命名构造函数字段来创建对象。
UPDATE: I have amended string
to be String
, however now when I update it I get the error:
更新:我已修改string
为String
,但是现在更新时出现错误:
error: constructor Mobile(java.lang.String,int,int,java.lang.String,int,java.lang.String) is already defined in class Mobile
This error comes up at the bottom of the page at:
此错误出现在页面底部:
public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution,
String MobileGPS) {
What does this error mean?
这个错误是什么意思?
The code so far:
到目前为止的代码:
/**
* to write a simple java class Mobile that models a mobile phone.
*
* @author (Lewis Burte-Clarke)
* @version (14/10/13)
*/
public class Mobile
{
// type of phone
private String phonetype;
// size of screen in inches
private int screensize;
// menory card capacity
private int memorycardcapacity;
// name of present service provider
private String serviceprovider;
// type of contract with service provider
private int typeofcontract;
// camera resolution in megapixels
private int cameraresolution;
// the percentage of charge left on the phone
private int checkcharge;
// wether the phone has GPS or not
private String GPS;
// instance variables - replace the example below with your own
private int x;
// The constructor method
public Mobile(String mobilePhoneType, int mobileScreenSize,
int mobileMemoryCardCapacity, String newserviceprovider, 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;
}
// A method to display the state of the object to the screen
public void displayMobileDetails() {
System.out.println("phonetype: " + phonetype);
System.out.println("screensize: " + screensize);
System.out.println("memorycardcapacity: " + memorycardcapacity);
System.out.println("cameraresolution: " + cameraresolution);
System.out.println("GPS: " + GPS);
System.out.println("serviceprovider: " + serviceprovider);
System.out.println("typeofcontract: " + typeofcontract);
}
public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution,
String 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;
}
}
class mymobile {
public static void main(String[] args) {
Mobile Samsung = new Mobile("Samsung", "3", "4", "8",
"GPS");
Mobile Blackberry = new Mobile("Blackberry", "3.", "4",
"8", "GPS");
Samsung.displayMobileDetails();
Blackberry.displayMobileDetails();
}
}
回答by Reimeus
回答by dtgee
string
should be uppercase S. You have your string type as lower case s
string
应该是大写的 S。你的字符串类型是小写的 s
private String phonetype;
Java is case-sensitive. String
is a class that extends from the Object class, which is why it's capitalized, just like Integer
. However, primitive types are not capitlized (i.e. boolean
, int
, char
).
Java 区分大小写。String
是一个从 Object 类扩展而来的类,这就是它大写的原因,就像Integer
. 但是,原始类型没有大写(即boolean
, int
, char
)。
回答by CamHart
Make the s in string capitalized. It's case sensative.
使字符串中的 s 大写。区分大小写。
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html