I get a failure every time I try and execute this - java

When I use Scanners or try to get a user input, I get the message:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':run'.
Process 'command 'C:\Program Files\Java\jdk-13.0.1\bin\java.exe'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date
When I just use a system.out.println();
It goes through successfully.
Here is my code:
/**
*
* #author boaz5
*/
import java.io.IOException;
import java.util.Scanner;
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException {
System.out.println("What is your name?");
Scanner name = new Scanner(System.in);
String nameString = name.next();
System.out.println("Hi," + nameString);
}
}
I'm not sure what I'm doing wrong. I am a complete newbie and this is one of my first Java projects. Thanks!

Not much to go on here, but I can give a couple suggestions to get started:
1.) Update your Gradle plug-in. The compilation issue may not be code related, but instead a problem with the tooling.
2.) If above fails replace the IOException with Exception and see if we get any further output.
Let us know

you should review your environment, I did copy your code and work for me.
12:26:02 AM: Executing task 'Test.main()'...
Task :compileJava
Task :processResources NO-SOURCE
Task :classes
Task :Test.main()
What is your name?
Alvaro
Hi,Alvaro
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See

There is no problem in your code. The code is running without any error.
I think you added the processor as a compile dependency. You should add it as 'provided'.

Related

how to fix "gradlew genSources"

I'm on windows 10, when I do "gradlew genSources" then this happened
Starting a Gradle Daemon, 7 stopped Daemons could not be reused, use --status for details
> Configure project :
Fabric Loom: 0.10.66
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\user\Downloads\MCJAVA\vector-addon\build.gradle'
* What went wrong:
Could not compile build file 'C:\Users\user\Downloads\MCJAVA\vector-addon\build.gradle'.
> startup failed:
General error during conversion: Unsupported class file major version 62
java.lang.IllegalArgumentException: Unsupported class file major version 62
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5s
I want to know how can i fix it and im not good at coding and my english is not that good, I still tried with --stacktrace it still have similir error please help me
(its have a lot more text in code but its too much and i dont think it important)

Java class file not compiling or running on Android Studio

Where I try to run code in Android studio, its not working and displaying error attached below. example:
package com.example.jerry;
public class Test {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Got error when running Java class Test.class. This is the error displaying:
5:06:58 PM: Executing task 'Test.main()'...
Executing tasks: [Test.main()] in project G:\JavaProject\Jerry
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\Shakil\AppData\Local\Temp\Test_main__1.gradle' line: 21
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Test.main()'.
> SourceSet with name 'main' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 271ms
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
5:06:58 PM: Task execution finished 'Test.main()'.

Sonarlint Gradle Task - Execution failed for task ':sonarlintMain'

Trying to use 'sonarlintMain' using Gradle 7.0.2_2 on 'openjdk version "15.0.2" 2021-01-19'
id ("name.remal.sonarlint") version "1.3.1"
Runs & displays:
> Task :sonarlintMain
219 SonarLint violations were found
[rank 1] [java:S2095] /Users/NOTiFY/IdeaProjects/GoStopHandle/src/main/java/com/gostophandle/ejb/DatabaseSchemaJSON.java:115:30
Resources should be closed
Connections, streams, files, and other classes that implement the Closeable interface or its
super-interface, AutoCloseable, needs to be closed after use. Further, that close call must be
made in a finally block otherwise an exception could keep the call from being made. Preferably,
when class implements AutoCloseable, resource should be created using "try-with-resources"
pattern and will be closed automatically.
Failure to properly close resources will result in a resource leak which could bring first the
application and then perhaps the box the application is on to their knees.
etc ...
At end shows:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sonarlintMain'.
> 219 SonarLint violations were found
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 32s
Publishing a build scan to scans.gradle.co:
1 task failure
The :sonarlintMain task failed.View task in console log
219 SonarLint violations were found
Found: https://remal.gitlab.io/gradle-plugins/plugins/name.remal.sonarlint/
Added:
sonarlint {
ignoreFailures = true
}
Runs:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 34s
18 actionable tasks: 16 executed, 2 up-to-date
Need more documentation etc. but will pass for the time.

No warning for unused import

I am building a gradle java project using sublime, instead of an IDE like eclipse. I have notice when I run the build task, I do not get any warnings about unused imports.
Is there a compiler option in java that can turn on my strict warnings? If so, how do I enable that in my build.gradle?
Thanks.
Warning on unused imports is not something the Java compiler currently handles: https://docs.oracle.com/en/java/javase/14/docs/specs/man/javac.html#examples-of-using--xlint-keys
You can use an external code style tool to take care of that for you. For example, with Spotless
plugins {
`java`
id("com.diffplug.gradle.spotless") version "4.0.0"
}
spotless {
java {
eclipse()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
and the following Java source with unused List import:
import java.util.List;
public class Example {
public static void main(String[] args) {
System.out.println("hello");
}
}
when I try to build the project, I will immediately get an error:
> Task :build FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:spotlessJava'.
> The following files had format violations:
src\main\java\io\mateo\gradle\build\Example.java
## -1,7 +1,5 ##
package╖io.mateo.gradle.build;
-import╖java.util.List;
-
public╖class╖Example╖{
\tpublic╖static╖void╖main(String[]╖args)╖{
Run 'gradlew spotlessApply' to fix these violations.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

Error building boofcv calibration app with gradle

I've followed build instructions from here:
https://boofcv.org/index.php?title=Tutorial_Camera_Calibration
and get this strange error message:
C:\boofcv\applications>gradle applicationsJar
Skipping integration/android because ANDROID_HOME has not been set! See integration/android/readme.txt
Skipping integration/boofcv-openkinect because boofcv-openkinect/libfreenect is missing! See integration/openkinect/readme.txt
Parallel execution is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task ':applications:applicationsJar' property 'rootSpec$1$1$2$1' during up-to-date check.
> A Jar can only accept a file or directory that exists: C:\boofcv\applications\build\osgi-classes
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
38 actionable tasks: 10 executed, 28 up-to-date
my boofcv version is 0.27.

Categories