linking TextIO to Eclipse Java Project [message #821835] |
Thu, 15 March 2012 17:55  |
Eclipse User |
|
|
|
Hope this is the right forum. This should have taken three minutes and I've lost the whole day on this.
I'm running Eclipse Eclipse SDK Version: 3.7.2 with the default workspace on C:\Documents and Settings\owner\workspace on windows xp. I'm using the jdk-7u3-windows-i586 version of Java.
Separately, I've downloaded TextIO.java (and in desperation even created a class for it). I've copied and pasted TextIO.java to every place I can think of, but the Eclipse IDE does not find it.
e.g. Here's the code for the class (and project) (periods used to show indents)
public class Exercise1v1 {
....public static void main(String[] args) {
.
........String usersName; // The user's name, as entered by the user.
........String upperCaseName; // The user's name, converted to upper case letters.
.
........System.out.print("Please enter your name: ");
........usersName = TextIO.getln();
.
........upperCaseName = usersName.toUpperCase();
.
........System.out.println("Hello, " + upperCaseName + ", nice to meet you!");
.....} // end main()
}
the error is "the method getln() is undefined for the type TextIO"
My Project is
Exercises1
..- src
....- default package
....- Exercise1v1,java
....- TextIO.java
..+ snippet
..+ JRE System Library [JavaSE 1.7]
....TextIO.java
|
|
|
|
Re: linking TextIO to Eclipse Java Project [message #1799133 is a reply to message #821835] |
Fri, 30 November 2018 05:22  |
Eclipse User |
|
|
|
For those of you foloowing a course that uses import textio.TextIO as you have discovered, this will not work in Eclipse.
There is a simple way around this.
Instead of importing textio.TextIO you can import Scanner.
So all you do is at the start of your program replace:
import textio.TextIO;
with import java.util.Scanner;
in the "main" enter the following code
Scanner scan = new Scanner( System.in );
And where TextIO is used amend the code.
Here are a couple of examples. (usersGuess is an integer and playAgain a boolean)
usersGuess = TextIO.getInt();
becomes usersGuess = keyboard.nextInt();
playAgain = TextIO.getlnBoolean();
becomes playAgain = keyboard.nextBoolean();
I hope this helps.
[Updated on: Fri, 30 November 2018 10:37] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.16332 seconds