2017-04-15 24 views
0

對於在使用地點附近定義的類,我得到「無法解析符號」錯誤。 我做了無效緩存並重新啓動了InteliJ幾次,但它沒有幫助。 還有什麼可能是錯的?InteliJ無法解析靠近它的名稱

enter image description here

class Vehicle(speed : Int){ 
    val mph : Int = speed 
    def race() = println("Racing") 

} 

class Car(speed: Int) extends Vehicle(speed){ 
    override val mph: Int=speed 
    override def race() = println("Racing Car") 
} 

class Bike(speed:Int) extends Vehicle(speed) { 
    override val mph:Int = speed 
    override def race() = println("Racing Bike") 
} 

object Test { 

    def main(args: Array[String]): Unit = { 
    println("Hello") 
val x = Bike(4) 
    } 
} 
+2

由於屏幕截圖中的代碼無法複製,您可以將代碼粘貼到問題中嗎? – ashawley

回答

1

編輯:該作品(不同的是,你缺少的測試對象在自行車上定義之前new關鍵字)

class Vehicle(speed : Int){ 
    val mph : Int = speed 
    def race() = println("Racing") 

} 

class Car(speed: Int) extends Vehicle(speed){ 
    override val mph: Int=speed 
    override def race() = println("Racing Car") 
} 

class Bike(speed:Int) extends Vehicle(speed) { 
    override val mph:Int = speed 
    override def race() = println("Racing Bike") 
} 

object Test { 

    def main(args: Array[String]): Unit = { 
    println("Hello") 
    val x = new Bike(4) 
    } 
} 

enter image description here

+0

它沒有幫助 - 它仍然無法解決它 –

+0

你忘了'new' @DraifKroneg – pedrorijo91

+0

它不適用於自行車的新功能。但是,如果其他代碼在您的InteliJ中正常工作,那麼它必定是我的InteliJ被破壞了。 –

0

你是試圖創建Bike對象沒有關鍵字new並沒有公司具有適當的def apply功能。似乎這混淆了IDEA。要直接創建課程,您需要使用new Bike