Eclipse is unable to locate System.in in java code [duplicate] - java

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 6 years ago.
I have the code:
import java.io.*;
...
public void test() {
...
InputStreamReader inputStream = new InputStreamReader(System.in);
...
}
but eclipse is not allowing the "in" part of the System.in.
When placing the '.' after System, I get offered many alternatives, but not 'in'.
the error message is given in eclipse is: "in cannot be resolved or is not a field".
I've been 'round in circles with it, but cannot see why - anyone have any ideas?
Running Eclipse on Debian Jessie.

Hope this helps, modify it as:
InputStreamReader inputStream = new InputStreamReader(java.lang.System.in);

Related

Selenium 'WebDriver cannot be resolved to a type, FirefoxDriver cannot be resolved to a type' (not a duplicate) [duplicate]

This question already has answers here:
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 4 years ago.
I am currently having a bad first time experience of using this forum, with my questions being repeatedly deleted as duplicates despite my explaining that the suggested fixes are not solving my problem. The cause of the first questioner’s error was incorrect jars, I appear to have the correct ones according to the list proposed in that thread.
This is my code:
package sanityTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/Users/lawrencedonohoe/Downloads/geckodriver");
WebDriver driver = new FirefoxDriver();
}
}
I am getting the following error:
Unresolved compilation problem: WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
I gather from other forum articles that this is due to not having the correct jars in my build path, or having one I shouldn't. I appear, however, to have all the jar files the aforementioned question's answerers suggest I need.
This a full list of the jars I have added:
client-combined-3.14.0-sources
client-combined-3.14.0
byte-buddy-1.8.15
commons-codec-1.10
commons-exec-1.3
commons-logging-1.2
guava-25.0-jre
httpclient-4.5.5
httpcore-4.4.9
okhttp-3.10.0
okio-1.14.1
Can someone please help me?
Please try following code, it is defining driver path manually and also If you are using linux environment, it can be related with permissions to read the drivers path :
System.setProperty("webdriver.gecko.driver","pathToYourDriver/geckodriver.exe");
WebDriver driver = new FirefoxDriver();

How this program compiled and run successfully? [duplicate]

This question already has answers here:
Java Label usage [duplicate]
(2 answers)
Closed 6 years ago.
The below program compiled successfully and run without any errors. As per my understanding is should have thrown error in line 4. Can somebody explain?
class Test{
public static void main(String args[]) {
// my favorite website is
http://www.stackoverflow.com/questions/ask
System.out.println("hello world");
}
}
No, it's not an error, "http:" works here as the name of the label and "//" starts the comments which is ignored.

Run external file Java [duplicate]

This question already has answers here:
Running Command Line in Java [duplicate]
(8 answers)
How to Execute Windows Commands Using Java - Change Network Settings
(5 answers)
What does "error: unreported exception <XXX>; must be caught or declared to be thrown" mean and how do I fix it?
(1 answer)
Closed 7 years ago.
How can I run an external file in Java?
Like opening a batch or a PDF file?
I want to add it to a jButton with Netbeans, so if somebody pushs on it, it will launch this file from a specified directory
Theres not a lot about this to find on the internet (except a web application, but it needs to be a file/batch/.exe ....
AS SAID its for Netbeans! Everytime I use those commands inside a Button Class:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("msg * hello");
}
I get an error for the line:
Process pr = rt.exec("msg * hello");
Which says:
unreported exception IOException; must be caught or declared to be
thrown
Now how do I launch an external file?
The Runtime class can be used to do this. You can get an instance of this class via the static method Runtime.getRuntime(). In the Runtime class are several exec() methods that should be what you need.
Finally, you may consider the ProcessBuilder class more convenient depending on how complex your needs are.

Website name in java program [duplicate]

This question already has answers here:
My java code has an obvious error. Why does it compile and run?
(2 answers)
Why doesn't putting a random http link in code cause a compilation error? [duplicate]
(2 answers)
Closed 9 years ago.
public class Main
{
public static void main(String[] args)
{
http://google.com
System.out.println("Welcome");
}
}
Why is this code not getting a compilation error? and why did it get a compilation error if we write this url name after System.out.println("Welcome"); ??
Because it's a label followed by a comment.

R.raw.anything cannot be resolved [duplicate]

This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 10 years ago.
I'm developing an android apps with Eclipse.
In my app, I try to read a file : data.xml. I put it in res/raw/, and to access it i'm supposed to use getRessources().openRawResource(R.raw.data);
But Eclipse show me an error : "data" cannot be resolved or is not a field.
But the field is in the gen/R.java !!!
public final class R {
public static final class raw {
public static final int data=0x7f040000;
}
}
Any ideas ?
Thanks
Solution :
Import the right R.java files !
import my_package.R;
Stop trusting ctrl+shift+O ...
I already faced this problem several weeks ago. You simply have to use com.example.R (where com.example is the name of your package), because your IDE thinks that you are using android.R by default.
Try this out.
Try to clean and rebuild your project!
Or just delete import android.R;.
If that data.xml is in raw folder but still its not resolved once Clean and build your project and check.
Still error check this : Opening raw file

Categories