Cloud vision api text detection showing syntax errors - java

I have downloaded Java Vision API project from Github.
I enabled billing for my project through developers console and got client_secret for my project. Later by adding an environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to my client_secret file. I'm able to do all the other operations like Labeling, face detection and Landmark detection. When I try to execute text_detection code I'm getting these errors. See Image here
public void indexDirectory(Path inputPath) throws IOException {
List<Path> unprocessedImages =
Files.walk(inputPath)
.filter(Files::isRegularFile)
.filter(index::isDocumentUnprocessed)
.collect(Collectors.toList());
Lists.<Path>partition(unprocessedImages, BATCH_SIZE)
.stream()
.map(this::detectText)
.flatMap(l -> l.stream())
.filter(this::successfullyDetectedText)
.map(this::extractDescriptions)
.forEach(index::addDocument);}
This is the code I've written and I'm getting the below errors.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Files cannot be resolved to a variable
Syntax error on tokens, delete these tokens
Syntax error on tokens, delete these tokens
Syntax error on token(s), misplaced construct(s)
Syntax error on tokens, delete these tokens
Syntax error on token "-", -- expected
Syntax error on tokens, delete these tokens
Syntax error on tokens, delete these tokens
Syntax error on token ":", EnhancedForStatementHeaderInit expected after this token
at com.google.cloud.vision.samples.text.TextApp.indexDirectory(TextApp.java:158)
at com.google.cloud.vision.samples.text.TextApp.main(TextApp.java:107)
I know that these are syntax error but still I'm unable to find any solution to make it work.
Can anyone please suggest me how I can get this to work.

Related

Apostrophe in FeignException shows like /u0027

I have a Feign client which I use to get information from SonarQube and when I'm trying to test request with wrong component name I have an issue with displaying apostrophes as unicode (/u0027).
Here's the test code:
void measuresSearchHistoryUnknownTest() {
assertThatExceptionOfType(FeignException.NotFound.class)
.isThrownBy(() -> sonarFeignClient.measuresSearchHistory(
"badProject",
String.join(",",
EnumUtils.getJsonValue(SonarMetric.BLOCKER_VIOLATIONS),
EnumUtils.getJsonValue(SonarMetric.CRITICAL_VIOLATIONS)
),
1,
10
)).withMessageContaining("Component key 'badProject' not found");
// )).withMessageContaining("Component key \\u0027badProject\\u0027 not found");
}
This test works only if use last line (commented line with "\u0027badProject\u0027"), but it fails if I use previous line (with common apostrophes):
Expecting throwable message:
<"[404] during [GET] to [*******/sonar/api/measures/search_history?component=badProject&metrics=blocker_violations%2Ccritical_violations&p=1&ps=10] [SonarFeignClient#measuresSearchHistory(String,String,int,int)]: [{"errors":[{"msg":"Component key \u0027badProject\u0027 not found"}]}]">
to contain:
<"Component key 'badProject' not found">
but did not.
Throwable that failed the check:
feign.FeignException$NotFound: [404] during [GET] to [*******/sonar/api/measures/search_history?component=badProject&metrics=blocker_violations%2Ccritical_violations&p=1&ps=10] [SonarFeignClient#measuresSearchHistory(String,String,int,int)]: [{"errors":[{"msg":"Component key \u0027badProject\u0027 not found"}]}]
If I look this link in a browser SonarQube shows me JSON with error message and common apostrophes (not unicode), so I think an issue somewhere in Feign.
I use "spring-cloud-starter-openfeign:3.0.1"
Maybe someone can help me with that? How can I prevent parsing of apostrophes to Unicode?

Error "Multiple markers at this line - Syntax error on token " returned when using selenium.setSpeed()

When I included selenium.setSpeed("2000"); inside my void main i got the syntax error "selenium cannot be resolved"
When I placed it outside my void main and inside my class I got the error :
"Multiple markers at this line - Syntax error on token ",", < expected - Syntax error, insert "SimpleName" to complete QualifiedName - Syntax error on token ".", # expected after this token - Syntax error, insert ")" to complete MethodDeclaration - Syntax error, insert "Identifier (" to complete MethodHeaderName"
Please do help me resolve this issue.
The ancient versions of Selenium of-coarse had a method as setSpeed() but this method had been deprecated long back. setSpeed() was used to control the speed of each step of your Automation Script. As the purpose of Automated Testing is to reduce the Validation Time so setting the speed of each line of your script execution through setSpeed() was contradictory. Hence setSpeed() was deprecated.
Incase you want to wait for a certain condition you can use either Implicit Wait or Explicit Wait i.e. WebDriverWait Class in-conjunction with ExpectedConditions.
Scanner input will not work if you try to use it at the beginning of a class. It will show syntax errors like this.
(Multiple markers at this line
- Syntax error, insert ")" to complete MethodDeclaration)
The solution is: You have to use Scanner input within the main method().

JFlex + BYACC/J: Syntax error

I am using JFlex + BYACC/J to parse a small language.
Everything works but the error message for any syntax error (yyerror) is simply
"Error: syntax error".
Is there any (easy) way of generating more verbose error messages? The -v (verbose) flag only generates a y.output file with a description of the state machine.
Goal is to have error messages such as: "Expected X before Y but found Z" or something similar.
EDIT (w.r.t comments):
Above goal can be achieved in Bison but it does not solve my problem with BYACC/J

Android Studio build file R broken

I am working on an android app which has worked and been tested many times. Today, however, in attempting to run the application for further testing, I have encountered the following error message:
C:\Users\1000\AndroidStudioProjects\WarofSol\app\build\generated\source\r\debug\com\blacktentdigital\warofsol\R.java
Error:(1251, 32) error: identifier expected
Error:(1251, 34) error: illegal start of type
Error:(1251, 35) error: identifier expected
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
>Information:BUILD FAILED
The problem is in the R.java file (as listed above). It is a generated file, so I've never touched it.
The offending line is this:
public static final class drawable {
public static final int 3=0x7f020000;
Hover over the offending line gives the following warning: "Identifier expected | Unexpected token"
Comparisons to other R files reveal that the "3" is not supposed to be a 3, and is evidently corrupted.
Attempts to replace the line or file with older backed-up versions have failed to produce any result because (evidently) the file is regenerating the wrong way each time I attempt the build, and I have no idea what might cause this. As I say, the problem sprang up suddenly without any provocation of which I am aware.
I've also attempted closing the program and restarting the computer to no avail.
Any ideas as to what might cause this and how it might be fixed?
I did get the Same error when i have defined a String in xml file like this.
<string name="3">Settings</string>
Error:
Error:(1426, 32) error: <identifier> expected
Error:(1426, 34) error: illegal start of type
Error:(1426, 35) error: <identifier> expected
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Solution: Resource name must begin with character.
So i have just change String like <string name="S3">Settings</string> and it worked.
So just check if you have any resource name 3 in all your resource file(string.xml, style.xml, attrs.xml) and folder(drawable, layout).
This is a quote from java documentation:
A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".
And you named drawable with digit, that caused the problem.

Syntax error on ; when allocating an array

I'm getting an error in Eclipse when trying to initialize the following array in the initializing section of my class:
Color[] colors;
colors = new Color[4];
This is the error I'm getting:
Syntax error on token ";", , expected
Where ";" refers to the semicolon on the first line.
Tried different variable types, gave the same error.
Here's some code on the official JDK tutorial section that seems the same to me:
http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
Thanks in advance, guys.
This is a correct syntax and does compile.
(Maybe the line before is a problem. Can you post it too)

Categories

Resources