I have a small program to scan an Integer from console, also I would like to use new line character as delimiter.
import java.util.Scanner;
public class TestScanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in).useDelimiter("\n");
System.out.println("Enter the int");
int testInt = scanner.nextInt();
System.out.println(testInt);
}
}
Intellij runs and exist normal way..
Where as Eclipse produce, java.util.InputMismatchException
In Run mode you can observe an exception, with debug mode, code will run with out any issues
Source : jdk1.8.0_161 ( Oracle )
Eclipse :
This is strange. Kindly help me to understand how this can be corrected. Thanking you!
Late but... if you're in Windows you should use "\r\n" instead of just "\n"
Related
I am using VS CODE to learn java. While debugging , it opens all the internal classes it encounters in the code.
For example:-
class test{
public static void main(String[] args) {
int x= 7;
int y = 8;
System.out.println("Hello World"); // opens prints stream class and executes each line per click of this print stream class
int z = x+y;
}
}
What I want - when the debugger hits System.out.println("hello world"); it prints hello world and moves on rather than opening the printstream class.
Pictures below:
google stepFilter vscode and use it.
I am setting the VM arguments in eclipse as -DFilePath="C:\file\txt"
But while calling this #FilePath# in java it is giving output as C:filetxt instead of C:\file\txt. This is resulting in file not found exception. Can anyone please help me on this..
The problem must be in how you are "calling this #FilePath#".
I tested with following code:
package test;
import java.io.File;
public class EnvPath {
public static void main(String[] args) {
String path = System.getProperty("FilePath");
System.out.println("Prop: " + path);
File file = new File(path);
System.out.println("File: " + file);
}
}
Started from Eclipse, as you described, or with java -DFilePath="C:\file\txt" test.EnvPath using Windows Command Prompt and using GNU bash - it always produces:
Prop: C:\file\txt
File: C:\file\txt
I have set up Hadoop v2.7 in my mac and i am able to start the Hadoop daemons.
I would like to write the MR program using eclipse, i need some help to get the hadoop on my eclipse, i would like to know the jar files to be added and basic set up guide
The following is my Driver class code and i couldn't execute it
public class MyJobDriver extends Configured implements Tool {
#Override
public int run(String[] args) throws Exception {
Configuration conf = getConf();
JobConf job = new JobConf(conf, MyJobDriver.class);
Path in = new Path(args[0]);
Path out = new Path(args[1]);
FileInputFormat.setInputPaths(job, in);
FileOutputFormat.setOutputPath(job, out);
job.setJobName("Patent");
job.setMapperClass(InverseMapper.class);
//Input Split consist two values separated by ","
//K1 and V1 type is Text
job.setInputFormat(KeyValueTextInputFormat.class);
job.set("key.value.separator.in.input.line",",");//Everything before the separator is the key and after is the value
job.setOutputFormat(TextOutputFormat.class);//Key and value written as string and separated by tab(default)
//when k1 and k2 are od same type and V1 and V2 are of same type
//we can skip job.setMapOutputKeyClass() and job.setMapOutputValueClass()
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
//jobClient communicates with the JobTrackers to start job across clusters
JobClient.runJob(job);
return 0;
}
public static void main(String[] args) throws Exception {
MyJobDriver driver = new MyJobDriver();
System.out.println("Calling the run method");
int exitCode = ToolRunner.run(driver, args);
System.exit(exitCode);
}
It is too much trouble track and retrieve the necessary jar file (there are many). Instead create a maven project in eclipse and add necessary dependencies as mentioned here https://hadoopi.wordpress.com/2013/05/25/setup-maven-project-for-hadoop-in-5mn/
this is the code from TIJ4#
The java code can compile and run in cmd window , but can not compile and run in eclipse .
//: io/MemoryInput.java
import java.io.*;
public class MemoryInput {
public static void main(String[] args)
throws IOException {
StringReader in = new StringReader(
BufferedInputFile.read("MemoryInput.java"));
int c;
while((c = in.read()) != -1){
System.out.print((char)c);
}
}
the wrong information about the code in eclipse is :
BufferedInputFile cannot be resolved
BufferedInputFile is not part of the package java.io. If you have that class in a library or in a certain folder you have to include it in Eclipse.
BufferedInputFile is not part of any default lib of java. So you have to add that class to your class path.
So I'm testing an eclipse plugin with SWTbot and I'm not getting the result I'm expect - when I cut the test down it turns out that the problem isn't with the bot it's with some code that I've copied accross from another part of the program (where it was fully functional)
The following code...
#RunWith(SWTBotJunit4ClassRunner.class)
public class Tests {
private static SWTWorkbenchBot bot;
#BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
}
#Test
public void maybeThisWillWork(){
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
System.out.println("A");
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
System.out.println("B");
}
#AfterClass
public static void sleep() {
System.out.println("In the sleep function");
bot.sleep(10000);
}
}
Gives me the output -
A
In the sleep function
Rather than the expected
A
B
In the sleep function
Any ideas?
you may need to run your test as JUnit plugin test. Have you tried that?
So it turns out that the answer is thus (also a nice advantage of stackoverflow is that I actually solved this somewhere else, remembered I'd had a similar problem and then had to come back to stackoverflow to remind myself of the details)
SWTBot isn't running in the UI thread proper hence the null pointer errors, what I had to do was use effectively:
Display display = bot.getDisplay();
display.syncExec(objectThatdoesthethingiwanttogetdoneintheUIthread);
System.out.println(objectThatdoesthethingiwanttogetdoneintheUIthread.results);
...and that got things working...