我在尝试导入课程时遇到错误
import com.DC.FTDataParser.XMLParser
val nodes = getXML
对象XMLParser不是com.DC.FTDataParser包的成员
此行有多个标记 - 未找到:值XMLParser - 未找到:值XMLParser
请找到XMLParser类。从Yahoo
加载XML很简单package com.DC.FTDataParser
class XMLParser //(fromccy: String, toccy: String)
{
import scala.xml._
import java.net._
import scala.io.Source
def getXML = {
XML.loadString(Source.fromURL(new URL("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDAUD%22,%22USDEUR%22,%22USDCAD%22,%22USDDKK%22,%22USDHKD%22,%22USDINR%22,%22USDJPY%22,%22USDKRW%22,%22USDBRL%22,%22USDMXN%22,%22USDCLP%22,%22USDPEN%22,%22USDCOP%22,%22USDNZD%22,%22USDNOK%22,%22USDSGD%22,%22USDSEK%22,%22USDCHF%22,%22USDGBP%22,%22USDUSD%22)&env=store://datatables.org/alltableswithkeys")).mkString)
}
/*
val exchange = nodes.foreach{ n =>
val Name = (n \\ "Name").text.takeRight(3)
val Rate = (n \\ "Rate").text
val date = (n \\ "Date").text
val Time = (n \\ "Time").text
val Ask = (n \\ "Ask").text
val Bid = (n \\ "Bid").text
//println(s"$Name, $Rate, $date")
}*/
}
答案 0 :(得分:1)
我看到两件事:
XMLParser
是一个班级。您需要有一个类的实例来调用getXML
方法。但是,查看代码,将其从class
更改为object
可能就足够了,然后您就可以调用其方法了。
getXML
, import com.DC.FTDataParser.XMLParser._
将会显示
醇>
但是,如果你想把它作为一个类,那么你可以做
val parser = new XMLParser
val nodes = parser.getXML