I am trying to write a sample program that can call use the main method of "SequenceFilesFromDirectory", which aims to convert a set of files into sequence file format.
public class TestSequenceFileConverter {
public static void main(String args[]){
String inputDir = "inputDir";
String outputDir = "outoutDir";
SequenceFilesFromDirectory.main(new String[] {"--input",
inputDir.toString(), "--output", outputDir.toString(), "--chunkSize",
"64", "--charset",Charsets.UTF_8.name()});
}
}
But the Eclipse tells me that what I did was wrong with the following error message
Multiple markers at this line
- Syntax error on token "main", = expected after this
token
- Syntax error on token(s), misplaced construct(s)
- SequenceFilesFromDirectory cannot be resolved
I think I did not use this method correctly, but I don't know how to fix it? Thanks a lot.
The following is how the SequenceFilesFromDirectory defines. The API link for SequenceFilesFromDirectory is http://search-lucene.com/jd/mahout/utils/org/apache/mahout/text/SequenceFilesFromDirectory.html
My guess is that you're missing an import line from the first section of your file:
import org.apache.mahout.text.SequenceFilesFromDirectory;
I think your purpose for using SequenceFilesFromDirectory is to convert doc files to sequence files. If so, better to call the run()/runSequential()/runMapReduce() methods ater creating an object of SequenceFilesFromDirectory, because SequenceFilesFromDirectory.main() internally calls haddop ToolRunner.run() method for processing.
Whereas the run methods of SequenceFilesFromDirectory do the actual processings.
Related
I have loaded the class file of a java program (that fetches data from an excel file and pushes it to a database and making connection to database using values from properties file) into the SQL developer.
Now I am trying to invoke the main method of the class file as below:
CREATE OR REPLACE PROCEDURE dataset
AS LANGUAGE JAVA
NAME 'data_design_1.main()';
It gives the following error:
Error: PL/SQL: Compilation unit analysis terminated
Error(3,1): PLS-00311: the declaration of "data_design_1.main()" is incomplete or malformed
Could anyone tell me why is this error occurring??
Thank you.
I think that the declaration of your main is this
public static void main(String[] args)
so the declaration of your PL/SQL wrapper is wrong.
You haven't posted the Java code
Maybe I'm wrong.
I wrote this simple program to try to read information from a txt file in my computer's D drive`
package readDisk;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
public class ReadDisk
{
public static void main(String[] args) {
Scanner input = new Scanner(Path.of("D:\\test.txt"), StandardCharsets.UTF_8);
String TestText = input.nextLine();
System.out.println(TestText);
}
}
I am getting an error message upon compilation which goes
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method of(String) is undefined for the type Path
at readDisk.ReadDisk.main(ReadDisk.java:9)
I am following a sample program found in the 11th Edition of Core Java Volume 1 and I've looked all over, trying to find where I've gone wrong to no avail. Any help will be appreciated.
As opposed to what some commenters say, the method you're trying to use does actually exist. The method in question takes a required first argument, and then a variable number of arguments, effectuated by the varargs construct, which means zero or more arguments.
But it is only available from Java 11 onwards. You need to check your Java version.
An alternative would be that you use scanner with another argument:
new Scanner(new File(D:/test.txt), StandardCharsets.UTF_8); or
new Scanner(Paths.get(D:/test.txt), StandardCharsets.UTF_8)
The constructors throw a FileNotFoundException and an IOException respectively. Make sure you either handle it or propagate it to the caller.
Note: A quick local test has shown me that this actually works for me. So if your code still throws a FileNoteFoundException, my guess is there is something otherwise wrong with the file or filename.
Try initializing your Scanner as below, you don't need Path for this :
Scanner input = new Scanner(new File("D:\\test.txt") , StandardCharsets.UTF_8);
The Path.of() method, added in JDK 11, requires a URI as parameter, not a String. For example,
Scanner input = new Scanner(Path.of(new URI("file:///D:/test.txt")), StandardCharsets.UTF_8);
Or you can simply use new Scanner(File), as other answer said.
Your code is fine Path::of method can take only one argument since the second one is vararg. Just make sure you are using java 11
I use rJava to call a java code from R, trying to call an algorithm from SPMF tool. I tried to use a wrapper function as in this question, but this did not work with the SPMF code.
this is my R code:
library(rJava)
.jinit()
.jaddClassPath ( "C:/mydrive/eclipse-workspace/myfile/src")
print(.jclassPath())
obj <- .jnew("AlgoFPGrowth_Strings")
s <- .jcall(obj, returnSig= "V", method="runAlgorithm",
"input.csv","output.txt") , 0.4 )
it gives me error ,method runAlgorithm with signature (D)V not found
this is the main in java:
public static void main(String[] args) throws Exception {
AlgoFPGrowth_Strings fpwindow=new AlgoFPGrowth_Strings();
String input="input.csv";
String output="output.txt";
double minsupp = 0.4;
fpwindow.runAlgorithm( input, output, minsupp);
fpwindow.printStats();
}
I tried to change returnSig value into S and Ljava/lang/String; but I got the same error, could not find the method
when I apply the code on different java code with simple method it works, is there any idea how can I change my code?
Try the below methods,
Change your jclassPath, where you directly specify the complete pathname of your jar file including the jar name, say /home/user/mypath/myclass_name.jar
Or, you can unzip your jar file in a folder and refer to that path in your jclassPath.
If, the above does not work,
Try to write the 'runAlgorithm' method in the same class where you are calling. I have faced issues with calling external libraries/classes.
I am trying to compile the ISO-SQL 2003 grammar from here
http://www.antlr3.org/grammar/1304304798093/SQL2003_Grammar.zip. All three versions of it can be found here http://www.antlr3.org/grammar/list.html.
These are the steps I followed,
java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Lexer.g
java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Parser.g
javac ANTLRDemo.java
ANTLRDemo.java file:
import org.antlr.runtime.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ANTLRDemo {
static String readFile(String path) throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, "UTF-8");
}
public static void main(String[] args) throws Exception {
ANTLRStringStream in = new ANTLRStringStream( readFile(args[0]) );
sql2003Lexer lexer = new sql2003Lexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
sql2003Parser parser = new sql2003Parser(tokens);
parser.eval();
}
}
First two steps work fine, then while compiling my main class I get a lot of errors related to Java syntax like these:
./sql2003Parser.java:96985: error: not a statement
$UnsignedInteger.text == '1'
./sql2003Parser.java:96985: error: ';' expected
$UnsignedInteger.text == '1'
./sql2003Parser.java:102659: error: unclosed character literal
if ( !(((Unsigned_Integer3887!=null?Unsigned_Integer3887.getText():null) == '01')) ) {
Please let me know if I am doing something wrong in setting up the parser. It would be helpful if someone can show me how exactly to setup this grammar using ANTLR.
Edit: After a little more fiddling, I think that these errors are caused by the actions present in lexer and parser rules. Is there a safe way to overcome this?
You are not doing anything wrong, ANTLR has never been able to generate a working Java parser from these grammar files.
According to a post by Douglas Godfrey to antlr-interest in Oct 2011:
I generated a C parser and lexer. they both generate and compile
successfully
on my machine with 8GB heap allocated to Antlr.
...
I don't believe that it will ever be possible to get a working parser in
Java. A C language parser on the other hand is quite possible.
Yes, basically you’re right. The grammar is broken. But also there is an error in your ANTLRDemo.java as there’s no eval() method in Parser class. You should call method with the name of any rule of the parser grammar e.g. query_specification(). In the grammar itself there were some errors looking as a typo, some undefined Java error() method calls, skip() calls in parser that are only suitable in lexer. You see all fixes in this commit. I’ve published my research in this GitHub repository.
I started to fix obvious errors of the grammar, which led to the compilation errors in generated java code. I had the same errors that you posted. Eventually I have fixed all Java syntax errors but faced another one which it impossible to fix directly because it originates from limitation of JVM, the compilation error: code too large. Reading ANTLR mailing list there was a hint to extract some static members of the huge classes into separate interfaces and “implement” them to have a sort of multiple inheritance. With trial and error I ended up with 6 interfaces ”imlemented” by parser in sql2003Parser.java.
But still there are 2 problems:
Wrong start rule. Douglas Godfrey wrote grammar that starts with sql2003Parser rule. Unfortunately if you call parser by this start rule, it won’t parse correctly even simplest select a from b. So I call parser by query_specification rule to parse SELECT clause only.
Some other errors in grammar. I didn’t dig too deep in the grammar but query_specification fails to parse some random complex SQLs.
I am brand new to Java. I am having an issue compiling a basic java program, and I am trying to understand why. (note that the TextIO class in the code is used in book I am studying to simplify the IO process, I don't believe that is where the issue is) Here is my code:
public class ProcessSales {
public static void main(String[] args) {
String ln;
String tmp;
int i;
int noval;
TextIO.readFile("sales.dat");
while (TextIO.eof() == false){
ln = TextIO.getln();
for (i = 0; i < ln.length(); i++) {
if (ln.charAt(i) == ':'){
tmp = ln.subString(i + 1);
}
} // end line for loop
try {
System.out.printf("%8.2f\n", Double(tmp.trim()));
}
catch (NumberFormatException e) {
noval++;
}
} // end of file while loop
System.out.printf("\nThere were a total of %d cities that didnt have data\n", noval);
} // end of main subroutine
} // end of ProcessSales class
The compile error I get is as follows:
[seldon#PrimeRadiant Exercises]$ javac ProcessSales.java
ProcessSales.java:15: cannot find symbol
symbol : method subString(int)
location: class java.lang.String
tmp = ln.subString(i + 1);
^
ProcessSales.java:20: cannot find symbol
symbol : method Double(java.lang.String)
location: class ProcessSales
System.out.printf("%8.2f\n", Double(tmp.trim()));
^
2 errors
Ive declared ln as a String object. The subString method is straight out of the java api for a String object. I'm not understanding why I'm getting a cannot find symbol compile error, especially if it lists the method signature and location right below the error.
I marked the questions as homework, since I am working out of a textbook, and I am looking to understand the issue, rather than a flat solution. However it is self study, and not part of any actual class (right now).
The great thing about the Java compiler is, it gives you alot of information to use in determining where problems exist in your code. For you, the first problem is here:
tmp = ln.subString(i + 1);
In this case you capitalized a letter that you shouldn't have. It should be:
tmp = ln.substring(i + 1);
Whenever you see compiler output saying 'cannot find symbol' its because the Java compiler could not find a method matching the outputted name, either due to a syntax error or missing dependency. For your second problem, you didn't post the appropriate code, but from the error message I can see you are missing the new keyword.
System.out.printf("%8.2f\n", Double(tmp.trim()));
Should be
System.out.printf("%8.2f\n", new Double(tmp.trim()));
If this is not your first programming language then I would recommend using an IDE like Eclipse, as it will give you auto-completion and syntax checking. It's a great tool for quickly learning the API's for the language. However if Java is your first programming language please do continue without hand-holding, as the hard knocks will cement in the lessons learned, faster.
I haven't verified any of this, I just looked at the source and the error messages.
The first error seems to be a case error. The Java String class does not have a subString method, it has a substring method, note the lowercase s. Reference
The second error would probably be resolved if you used new Double or Double.valueof instead of Double. This is because you are probably trying to construct a new Double object and using new operator or the valueof method in the Double class do this for you. Reference
In Java, method names are case sensitive. Check back with the String API specification for the correct "casing".
Regarding your first error, you have a typo. It should be ln.substring(i+1) not ln.subString(i+1). All source code text in Java is case sensitive.
Regarding your second error, you need to use the new keyword to instantiate the Double object. Without new, the compiler is not looking for the constructor; instead it is looking for a method Double within your ProcessSales class and cannot find it.