Created singleton object can't be detected in main function (Scala)
up vote
0
down vote
favorite
Singleton object LongLines which I created can't be recognized in object with main function (FindingLines). I put their files (LongLines.scala, FindingLines.scala ) in /src/main/scala/com/files/lines directory. Program code should have to find in particular file the lines which length is greater than parameter width.
Codes:
1) LongLines.scala (version from book I learn):
package com.files.lines
import scala.io.Source
object LongLines {
def processFile(filename: String, width: Int) {
val source = Source.fromFile(filename)
for (line <- source.getLines())
processLine(filename, width, line)
}
private def processLine(filename: String,
width: Int, line: String) {
if (line.length > width)
println(filename +": "+ line.trim)
}
}
2) LongLines.scala (my own version):
package com.files.lines
import scala.io.Source._
import java.nio.files.Paths._
object LongLines {
def processFile(filePath: String, width:Int): Unit = {
val path = get(filePath)
val fileName = path.getFileName.toString
val lines = fromFile(filePath).getLines().toList
for (line<-lines) processLines(fileName,line,width)
}
private def processLines(fileName: String, line: String, width: Int): Unit = {
if (line.length() > width) println(s"$fileName: $line");
}
}
3) FindingLines.scala (book version I used - only version):
package com.files.lines
object FindLongLines {
def main(args: Array[String]) = {
val width = args(0).toInt
for (arg <- args.drop(1))
LongLines.processFile(arg, width)
}
}
Error (compiled from linux terminal):
After I compiled program with my version and book version of LongLines.scala (separately, of course):
scalac FindingLines.scala
I've got this error:
FindLongLines.scala:15: error: not found: value LongLines
LongLines.processFile(arg, width)
^
one error found
package singleton main
add a comment |
up vote
0
down vote
favorite
Singleton object LongLines which I created can't be recognized in object with main function (FindingLines). I put their files (LongLines.scala, FindingLines.scala ) in /src/main/scala/com/files/lines directory. Program code should have to find in particular file the lines which length is greater than parameter width.
Codes:
1) LongLines.scala (version from book I learn):
package com.files.lines
import scala.io.Source
object LongLines {
def processFile(filename: String, width: Int) {
val source = Source.fromFile(filename)
for (line <- source.getLines())
processLine(filename, width, line)
}
private def processLine(filename: String,
width: Int, line: String) {
if (line.length > width)
println(filename +": "+ line.trim)
}
}
2) LongLines.scala (my own version):
package com.files.lines
import scala.io.Source._
import java.nio.files.Paths._
object LongLines {
def processFile(filePath: String, width:Int): Unit = {
val path = get(filePath)
val fileName = path.getFileName.toString
val lines = fromFile(filePath).getLines().toList
for (line<-lines) processLines(fileName,line,width)
}
private def processLines(fileName: String, line: String, width: Int): Unit = {
if (line.length() > width) println(s"$fileName: $line");
}
}
3) FindingLines.scala (book version I used - only version):
package com.files.lines
object FindLongLines {
def main(args: Array[String]) = {
val width = args(0).toInt
for (arg <- args.drop(1))
LongLines.processFile(arg, width)
}
}
Error (compiled from linux terminal):
After I compiled program with my version and book version of LongLines.scala (separately, of course):
scalac FindingLines.scala
I've got this error:
FindLongLines.scala:15: error: not found: value LongLines
LongLines.processFile(arg, width)
^
one error found
package singleton main
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Singleton object LongLines which I created can't be recognized in object with main function (FindingLines). I put their files (LongLines.scala, FindingLines.scala ) in /src/main/scala/com/files/lines directory. Program code should have to find in particular file the lines which length is greater than parameter width.
Codes:
1) LongLines.scala (version from book I learn):
package com.files.lines
import scala.io.Source
object LongLines {
def processFile(filename: String, width: Int) {
val source = Source.fromFile(filename)
for (line <- source.getLines())
processLine(filename, width, line)
}
private def processLine(filename: String,
width: Int, line: String) {
if (line.length > width)
println(filename +": "+ line.trim)
}
}
2) LongLines.scala (my own version):
package com.files.lines
import scala.io.Source._
import java.nio.files.Paths._
object LongLines {
def processFile(filePath: String, width:Int): Unit = {
val path = get(filePath)
val fileName = path.getFileName.toString
val lines = fromFile(filePath).getLines().toList
for (line<-lines) processLines(fileName,line,width)
}
private def processLines(fileName: String, line: String, width: Int): Unit = {
if (line.length() > width) println(s"$fileName: $line");
}
}
3) FindingLines.scala (book version I used - only version):
package com.files.lines
object FindLongLines {
def main(args: Array[String]) = {
val width = args(0).toInt
for (arg <- args.drop(1))
LongLines.processFile(arg, width)
}
}
Error (compiled from linux terminal):
After I compiled program with my version and book version of LongLines.scala (separately, of course):
scalac FindingLines.scala
I've got this error:
FindLongLines.scala:15: error: not found: value LongLines
LongLines.processFile(arg, width)
^
one error found
package singleton main
Singleton object LongLines which I created can't be recognized in object with main function (FindingLines). I put their files (LongLines.scala, FindingLines.scala ) in /src/main/scala/com/files/lines directory. Program code should have to find in particular file the lines which length is greater than parameter width.
Codes:
1) LongLines.scala (version from book I learn):
package com.files.lines
import scala.io.Source
object LongLines {
def processFile(filename: String, width: Int) {
val source = Source.fromFile(filename)
for (line <- source.getLines())
processLine(filename, width, line)
}
private def processLine(filename: String,
width: Int, line: String) {
if (line.length > width)
println(filename +": "+ line.trim)
}
}
2) LongLines.scala (my own version):
package com.files.lines
import scala.io.Source._
import java.nio.files.Paths._
object LongLines {
def processFile(filePath: String, width:Int): Unit = {
val path = get(filePath)
val fileName = path.getFileName.toString
val lines = fromFile(filePath).getLines().toList
for (line<-lines) processLines(fileName,line,width)
}
private def processLines(fileName: String, line: String, width: Int): Unit = {
if (line.length() > width) println(s"$fileName: $line");
}
}
3) FindingLines.scala (book version I used - only version):
package com.files.lines
object FindLongLines {
def main(args: Array[String]) = {
val width = args(0).toInt
for (arg <- args.drop(1))
LongLines.processFile(arg, width)
}
}
Error (compiled from linux terminal):
After I compiled program with my version and book version of LongLines.scala (separately, of course):
scalac FindingLines.scala
I've got this error:
FindLongLines.scala:15: error: not found: value LongLines
LongLines.processFile(arg, width)
^
one error found
package singleton main
package singleton main
edited Nov 11 at 1:36
asked Nov 9 at 3:10
Marko Gavranovic
112
112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Solution:
1) I removed "package com.file.lines" from both files (FindingLines.scala, LongLines.scala) - that means I need not to remove those files in this package (directory). Those two files could stay in src/main/scala directory.
2) scalac FindingLines.scala LongLines.scala
3) scala FindingLines.scala 45 ~/workspace/Rational/src/Rational.scala
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Solution:
1) I removed "package com.file.lines" from both files (FindingLines.scala, LongLines.scala) - that means I need not to remove those files in this package (directory). Those two files could stay in src/main/scala directory.
2) scalac FindingLines.scala LongLines.scala
3) scala FindingLines.scala 45 ~/workspace/Rational/src/Rational.scala
add a comment |
up vote
0
down vote
Solution:
1) I removed "package com.file.lines" from both files (FindingLines.scala, LongLines.scala) - that means I need not to remove those files in this package (directory). Those two files could stay in src/main/scala directory.
2) scalac FindingLines.scala LongLines.scala
3) scala FindingLines.scala 45 ~/workspace/Rational/src/Rational.scala
add a comment |
up vote
0
down vote
up vote
0
down vote
Solution:
1) I removed "package com.file.lines" from both files (FindingLines.scala, LongLines.scala) - that means I need not to remove those files in this package (directory). Those two files could stay in src/main/scala directory.
2) scalac FindingLines.scala LongLines.scala
3) scala FindingLines.scala 45 ~/workspace/Rational/src/Rational.scala
Solution:
1) I removed "package com.file.lines" from both files (FindingLines.scala, LongLines.scala) - that means I need not to remove those files in this package (directory). Those two files could stay in src/main/scala directory.
2) scalac FindingLines.scala LongLines.scala
3) scala FindingLines.scala 45 ~/workspace/Rational/src/Rational.scala
edited Nov 11 at 1:40
answered Nov 11 at 1:19
Marko Gavranovic
112
112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219314%2fcreated-singleton-object-cant-be-detected-in-main-function-scala%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown