Java 错误 - 不是声明,这是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19473424/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:34:42  来源:igfitidea点击:

Java error - not a statement, what does this mean?

java

提问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.

我试图让我的代码创建新的构造函数对象,我需要创建一个移动电话对象。我尝试命名构造函数字段来创建对象。

when I compile my code on this line this.Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS");I get this error: not a statement, what does this mean??

当我在这一行编译代码时,出现此this.Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS");错误:不是语句,这是什么意思?

UPDATED CODE!

更新代码!

my code:

我的代码:

   /**
 * 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,int mobilecameraresolution,String mobileGPS, String newserviceprovider) {
        this.phonetype =  mobilephonetype;
        this.screensize = mobilescreensize;
        this.memorycardcapacity = mobilememorycardcapacity;
        this.cameraresolution = mobilecameraresolution;
        this.GPS = mobileGPS;
        this.serviceprovider = newserviceprovider;
        this.typeofcontract = 12;
        this.checkcharge = checkcharge;
        // you do not use this ones during instantiation,you can remove them if you do not need or assign them some  default values 


        Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");
        1024 = screen size;
        2 = memory card capacity;
        3=resolution;
        GPS = gps;
       "verizon"=service provider;
        typeofcontract = 12;
        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);

    }



}

 class mymobile {
    public static void) {
        Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");
        Mobile Blackberry = new Mobile("Blackberry", "3.", "4","8", "GPS");
        Samsung.displayMobileDetails();
        Blackberry.displayMobileDetails();
    }
}

any answers and replies would be greatly appreciated!

任何答案和答复将不胜感激!

回答by ds1

Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS");

There's a comma missing after parameter value 3. I'd say that's your culprit.

参数值 3 后缺少一个逗号。我会说这是你的罪魁祸首。

回答by poohdedoo

Its a compilation error, it means The compiler was expecting a statement and you gave it something else please refer

它是一个编译错误,这意味着编译器正在等待一个语句,你给了它其他的东西,请参考

Should be

应该

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 

回答by Obicere

this.2 = memory card capacity;
this.3=resolution;

Makes no sense at all.

完全没有意义。

You can't assign values to a literal (2, 3).

您不能为文字 (2, 3) 赋值。



Edit: you would also need to fix this:

编辑:您还需要解决此问题:

Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");

As stated by other members.

正如其他成员所说。

回答by baifuyou

Mobile is a class,"this" stand for current object.So,You can't use "this" for Mobile.You should:

Mobile 是一个类,“this”代表当前对象。所以,你不能对 Mobile 使用“this”。你应该:

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");

回答by Dave Newton

    Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");
    1024 = screen size;
    2 = memory card capacity;
    3=resolution;
    GPS = gps;
   "verizon"=service provider;
    typeofcontract = 12;
    checkcharge = checkcharge;

You need to replace the numbers in your new Mobilector call with reasonable values, as described by what must be comments/notes below, e.g., where you have a 1put in the resolution (which makes no sense unless it's indexed or something), where you have a 2put in the memory card capacity, where there's a 3put in the resolution, etc.

您需要new Mobile用合理的值替换ctor 调用中的数字,如下面的注释/注释所描述的那样,例如,您1在分辨率中放置的位置(除非已编入索引或其他内容,否则没有任何意义),您有一个2放在存储卡容量,那里是一个3决议,等放

Then either comment out the lines that are garbage, or, preferably, delete them.

然后要么注释掉垃圾行,要么最好删除它们。