Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.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编译器错误:不是语句,这意味着什么?_Java - Fatal编程技术网

Java编译器错误:不是语句,这意味着什么?

Java编译器错误:不是语句,这意味着什么?,java,Java,你好,我得到这个错误:不是一个语句,错误是在第130行,returnphonetype 而且我不能让它像以前那样编译,没有语法错误 我的代码: public class Mobile { // type of phone private String phonetype; // size of screen in inches private int screensize; // memory card capacity private int memorycardca

你好,我得到这个错误:不是一个语句,错误是在第130行,returnphonetype

而且我不能让它像以前那样编译,没有语法错误

我的代码:

public class Mobile

{
    // type of phone
private String phonetype;
    // size of screen in inches
private int screensize;
    // memory card capacity
private int memorycardcapacity;
    // name of present service provider
private String mobileServiceProvider;
    // type of contract with service provider
private int mobileTypeOfContract;
    // camera resolution in megapixels
private int cameraresolution;
    // the percentage of charge left on the phone
private int chargeUp;
    // wether the phone has GPS or not
private int switchedOnFor;
    // to simulate using phone for a period of time
private int charge;
    // checks the phones remaining charge
private String provider;
    // simulates changing the provider
private String GPS; 
    // instance variables - replace the example below with your own


  // The constructor method

public Mobile(String mobilephonetype, int mobilescreensize,
int mobilememorycardcapacity, String mobileServiceProvider, int mobileTypeOfContract, int mobilecameraresolution, String mobileGPS, int chargeUp,int switchedOnFor, String changeProvider,int getBalance) {
     // initialise the class attributes from the one given as parameters in your constructor.
}


/**
* Other constructor
*/
public Mobile (int cost) {
    // initialise cost(?) attribute that actually doesn't seem to exist?
}

 /**
*returns a field price.
    */
public int getPrice()
   {
return price;
    }

        //this.serviceprovider = newserviceprovider;
        //this.typeofcontract = 12;
        //this.checkcharge = checkcharge;
        //this.changeProvider = giffgaff;

  //Mobile samsungPhone = new Mobile(
 //   "Samsung" // String mobilephonetype
//,   1024    // intmobilescreensize
//,   2      // intmobilememorycardcapacity
//,   8       // intmobilecameraresolution
//,   "GPS"    //String mobileGPS
//,   "verizon" // String newserviceprovider
//,    "100" // intchargeUp
//,    "25" // intswitchedOnFor
//,    "25" // intcheckCharge
//,     "giffgaff"// String changeProvider
//);


        //typeofcontract = 12;
        //checkcharge = checkcharge;


    //Mutator for newserviceprovider
public void setmobileServiceProvider(String newmobileServiceProvider)
   {
mobileServiceProvider = newmobileServiceProvider;
   }
   //Mutator for contracttype
public void setmobileTypeOfContract(int newmobileTypeOfContract)
   {
mobileTypeOfContract = newmobileTypeOfContract;
   }
   //Mutator for chargeUp
public void setchargeUp(int chargeUp)
   {
this.chargeUp = chargeUp;
   }
   //Mutator to simulate using phone for a period of time
public void switchedOnFor(int switchedOnFor)
   {
this.switchedOnFor = switchedOnFor;
    }
   //Accessor for type of phone
public String getType()
   {
return phonetype;
   }
   //Accessor for provider
public String getprovider()
   {
return mobileServiceProvider;
   }
   //Accessor for contract type
public int getContractType()
   {
return mobileTypeOfContract;
   }
    //Accessor for charge
public int getCharge()
   {
return chargeUp;
   }
    //Accessor which checks the phones remaining charge
public int checkCharge()
   {
return checkCharge;
   }
    // simulates changing the provider
public void changeProvider()
   {
provider = changeProvider;
   }
//returns the amount of change due for orders of mobiles. 
public int getBalance()
   {
return balance;
   }
    // 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("mobileServiceProvider: " + mobileServiceProvider);
System.out.println("mobileTypeOfContract: " + mobileTypeOfContract );
} 

      /**
 * The mymobile class implements an application that
 * simply displays "new Mobile!" to the standard output.
 */
public class mymobile {
public void main(String[] args) {
System.out.println("new Mobile!"); //Display the string.
    }
}
public static void buildPhones(){
Mobile Samsung = new Mobile("Samsung",3,4,"verizon",8,12,"GPS",100,25,"giffgaff");  
Mobile Blackberry = new Mobile("Samsung",3,4,"verizon",8,12,"GPS",100,25,"giffgaff");     
}    
public static void main(String[] args) {
buildPhones();
}  

}

非常感谢您的回答、回复和帮助,因为我无法像以前那样编译它,而且没有语法错误。

请在
返回
和变量名
电话类型
之间添加空格:

return phonetype;

注:您的代码中有不止一个问题

代码中有许多问题:

缺少空格:

return phonetype;
缺少成员变量:

private int balance;

   public int getBalance()
   {
return balance;
    }  
还有一个类似以下线条的外观:

public void setchargeUp(int chargeUp)   
{ 
chargeUp = chargeUp;    
}

没有错误,但该方法是无用的,因为您只是更改了一个局部变量,应该使用
this.chargeUp
来使用成员值。

您不了解错误的哪一部分?你认为那条线是干什么的?(提示:您制作了一个应该能够识别的简单类型)在
return
phonetype
之间放置一个空格:
return phonetype。看起来你需要在很多地方这样做。。。。当然,从
getType
checkCharge
的所有getter都是一样的。尽管听起来有点油嘴滑舌,但这些类型的错误(a)一旦你进行了一些发现它们的练习,就很容易发现,(b)能够发现它们非常重要(这听起来可能是一项无趣的技能,但就像一名赛车手不知道油门在哪里一样)。我不知道你在放弃和寻求帮助之前在这方面花了多少时间,但在寻求帮助之前确保你自己不能解决语法错误确实会对你有好处。这是一项值得练习的技能。抱歉,伙计们,现在给我一个错误:方法get Balance已经在类Mobile中定义,第142行:public int getBalance()这是因为您定义了两次,删除其中一个:)再次抱歉,伙计们,现在给我一个错误:找不到符号-可变价格,第56行:退货价格;