Why is StdIn.java Not Working in My Program?

  • Context: Java 
  • Thread starter Thread starter Hiche
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around issues related to using StdIn and StdOut in a programming context, specifically within the Eclipse IDE. Participants explore potential reasons for errors encountered when attempting to use these classes, including file placement and import statements.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an error when trying to use StdIn and StdOut, questioning if they are implementing it correctly by placing StdIn.java in the same folder as their source file.
  • Another participant suggests that an import statement might be necessary at the top of the code to resolve the issue.
  • A later reply indicates that even after adding the import statement, the error persists, specifically stating "StdIn cannot be resolved," while confirming that the StdIn.java file is in the correct directory.
  • One participant concludes that refreshing the project in Eclipse resolved the issue, stating that the import statement is not needed when the .java files are in the same directory.

Areas of Agreement / Disagreement

The discussion reflects a lack of consensus on the necessity of the import statement and the correct procedure for using StdIn and StdOut, with some participants suggesting different solutions to the same problem.

Contextual Notes

Participants do not clarify the specific conditions under which the import statement is necessary or the implications of file placement in different IDE configurations.

Hiche
Messages
82
Reaction score
0
I want to use StdIn and StdOut in my program as instructed. Our teacher told us to put the StdIn.java file inside the same folder as the source file (the program I am writing). But that is not working. Always gives me an error when I use the commands.

Am I doing it wrong? Is there another way?

Code:
StdOut.print or StdIn.readIn()
(for example)
 
Technology news on Phys.org
I think you might be missing an import statement at the top of your code. It would look like this:
Code:
import StdIn;
// any other imports
.
.
.
<your code>
 
I added the import statement but the error keeps appearing: "StdIn cannot be resolved". I'm positive that I placed the StdIn.java file in the same directory as my program. I am using Eclipse as an IDE so the .java files are usually in a folder called src, where I also put the StdIn.java.
 
Never mind. I just had to refresh my project. The import statement is not really needed when we place the .java files in the same directory.
 

Similar threads

Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
14
Views
4K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 12 ·
Replies
12
Views
11K
Replies
7
Views
3K
  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
6
Views
3K