2016-09-01 4 views
0

私はScalaのFunctional Programmingに関するMartin OderskyのMOOCを使っています。彼のLecture 3.2では、Eclipse IDEを使用してパッケージに格納されたクラスを参照する方法を示しています。しかし、私はIntelliJ IDEで作業しており、結果を再現するのに問題があります。私はSOとGoogleを見てみましたが、質問は高度なパッケージ関連の問題です。IntelliJ Scalaの問題を参照するときの問題

要するに、week3というパッケージがあり、その中に2つのファイルがあります。 最初のコンテンツとのRational Scalaのクラスファイルである:

package week3 

class Rational(x: Int, y: Int) { 
    require(y != 0, "denominator must be nonzero") 
    def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) 
    val g = gcd(x, y) 
    def numer = x/g 
    def denom = y/g 

    def this(x: Int) = this(x, 1) 
    def + (that: Rational): Rational = { 
    new Rational(
     numer * that.denom + denom * that.numer, 
     denom * that.denom) 
    } 

    def unary_- : Rational = new Rational(-numer, denom) 
    def - (that: Rational) = this + -that 
    def < (that: Rational) = this.numer * that.numer < this.denom * that.numer 
    def max(that: Rational) = if (this < that) that else this 
    override def toString = { 
    numer+ "/" + denom 
    } 
} 

そして第二のファイルは、以下のコードでスクラッチScalaのファイルです。彼は次の画像で結果を得る。

object scratch { 
    new week3.Rational(1,2) 
} 

Results

私の試み:私は私のsrcフォルダ内「week3」パッケージを作成し、week3パッケージ内のクラスファイルに合理ためのコードを含むことにより、IntelliJの中に同じ結果を再現しようとしました。次の私は、コードをsrcフォルダ内Scalaのワークシートを作成:

new week3.Rational(1,2) 

IDEはないフラグすべてのエラーを行いますが、何も右のインタラクティブ出力に表示されません。また、ワークシートを評価しようとすると、エラーが返されます。 Error ... not found

適切なトラックに私を設定してください。

答えて

1

[インタラクティブモード]チェックボックスの横にある[プロジェクトを作成]チェックボックスをオンにします。それはこの問題を解決するはずです。私は、この刺激性の問題を自分自身に直面していた:)

enter image description here

+0

トリックをやったおかげサマールを、! – beginner

+1

あなたは大歓迎です:私はこれについて多くの髪を無駄にしました! – Samar

+0

これらの毛は無駄な仲間ではなかった – beginner