How to access methods from main regarding an array [duplicate] - java

There was error occurred in Line 14.
Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - Erroneous sym type:
Hard to find solution.
package example;
public class Num
{
public static void main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5");
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s).doubleValue()); //Line 14
System.out.println(x);
}
catch (NumberFormatException e)
{
System.out.println("Wrong Number");
}
}
}

The code you provided runs fine on my computer.
I'm guessing you are using Netbeans and may be affected by a bug.
Try this:
Open the project properties, select the Build-Compiling, uncheck "Compile on save" and rerun the application. This will make sure all your source code becomes recompiled before running it.
Link: https://forums.netbeans.org/topic43241.html

This is a common issue which I get while working. What I do is clean and build the project. It solves the problem.
Right Click on the project name >> Clean and build

Download/install JDK major version number the same as NetBeans.
i.e. If You have NetBeans 9 version, but your JDK is version 10,then try use NetBeans 10 version... or download/install JDK 9 (the same as NetBeans).
Create new java platform for new jdk installation.
Open netbeans menubar->tools->Java Platforms->Add Platform
Specify the folder that contains the Java platform as well as the sources and Javadoc needed for debugging.
Set new java platform to your project
Right click on project ->properties->Libraries->Java Platform->select the jdk version that same as NetBeans
Select source format of your project
Right click on project ->properties->Sources->Sources/binary format->select the jdk version that same as NetBeans.
If it still gives errors like,
Exception in thread "main" java.lang.RuntimeException:
at javaapplication2.JavaApplication2.main(JavaApplication2.java:1)
C:\Users\James\AppData\Local\NetBeans\Cache\dev\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\James\AppData\Local\NetBeans\Cache\dev\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 1 second)
do as "sinclair" has mentioned above.
Open the project properties, select the Build-Compiling, uncheck "Compile on save" and rerun the application. This will make sure all your source code becomes recompiled before running it.

I received this error after I'd changed the type of a function parameter and it was the calling page that was in error - but I didn't see this until a magical Clean and Build pointed me to the actual issue!

I got this error message because I copied and pasted code without including the package name. I added the package name and it was fixed.

in my case
i have solved using import with package name and class name
like this import package.class1;

Please uncheck "Compile on save"

Related

Got error: > Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Execution failed for task ':Main.main()'.
Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
This is a java project with Gradle. Not sure what this error means.
This is a very generic error which I've faced as well with my Java Gradle Spring-Boot project. The reason being it so difficult to debug is that it doesn't give out any useful clue as to where the error occurred even if you provide the --stacktrace or --debug arguments to your gradle bootRun command.
However this can be easily determined if you wrap your Spring-Boot bootstrapper code in a try-catch and print the exception stacktrace as below:
#SpringBootApplication
public class MyApplicationServer {
public static void main(String[] args) {
try {
SpringApplication.run(MyApplicationServer.class, args);
} catch (Exception e) {
e.printStackTrace();
}
}
}
In my case, the exception was due to an unquoted special character (*) in application.yml which lead to a parsing failure. Excerpt of stacktrace below:
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application-local.yml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:535)
...(truncated logs)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
at com.ekart.citylogistics.payout.MyApplicationServer.main(MyApplicationServer.java:24) Caused by: while scanning an alias in 'reader', line 5, column 44:
... endpoints.web.exposure.include: *
^ expected alphabetic or numeric character, but found (10) in 'reader', line 5, column 45:
... ndpoints.web.exposure.include: *
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanAnchor(ScannerImpl.java:1447)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchAlias(ScannerImpl.java:918)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:366)
...(truncated logs)
This error is actually very general. I saw this error in my Scala project too. You need to click on the parent error with the line main(), which would show you the actual error. In my case, it is because I didn't download a specific file and there is a null pointer issue. Hope this helps!
For those who use IntelliJ IDE, if the solutions above don't work for your project, I have another solution:
Prefereces->Build, Exectution, Deployment->Build Tools->Gradle->Build and run
change "build and run using" and "run testing using" from Gradle to IntelliJ IDEA, then reload all Gradle projects
build and run
reload Gradle projects
This error goes away after updating IDE Compiler version rightly when you have multiple JDK installed on your machine (In my Mac, had JDK8 and JDK11). You may need to restart IDE once you make changes if needed. As in my case IntelliJ IDE, It works after doing invalidate cache and restart IDE.
Try clicking on the parent error with the line Main.main(). This should show you the actual error that occurred. For me, this was occurring because I hadn't set up a database connection in the application.properties file. Hope this helps.
This error maybe due to the port already being in use. Try again after closing other running instances of the application.
Hope this works!

How to create executable (.exe) file for any platform using Sikuli-script + Java + Eclips IDE

I have create java application using sikuli-script(latest version 1.0.1).
I added the sikuli-script.jar to the Referenced Libraries (I configured using this answer Answer Link)
java code folder structure -->
Java code -->
package com.example.sikuli;
import org.sikuli.script.*;
import java.util.concurrent.TimeUnit;
public class TestSikuli {
public static void main(String[] args) {
Screen s = new Screen();
App app = new App("C:/Program Files/Mozilla Firefox/firefox.exe");//firefox path
try{
app.focus();
TimeUnit.SECONDS.sleep(2);
s.click("imgs/1391152193781.png", 0);//url bar image
s.type(null, "http://www.google.lk", 0);
s.click("imgs/1391152289812.png", 0);//click search image
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
After that i set the the Run Configutrtion such as PATH and SIKULI_HOME
Next I run the code it's working properly.
Then I create .exe using launch4j and according to this site instructions --> How to Create an Executable File from Eclipse
After that i run the .exe file from command prompt then following errors occurred. Please help me.
Error -->
[error] ResourceLoaderBasic: check: libs dir is empty, has wrong content or is outdated
[action] ResourceLoaderBasic: check: Please wait! Trying to extract libs to: C:\Documents and Settings\Dell\SikuliX\libs
[error] ResourceLoaderBasic: loadLib: Fatal Error 109: not found: C:\Documents and Settings\Dell\SikuliX\libs\VisionProxy.dll
[error] Terminating SikuliX after a fatal error(109)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run againwith a Debug level of 3. You might paste the output to the Q&A board.
--1. when programming in Java using Sikuli, you should always use sikuli-java.jar (sikuli-ide.jar contains much stuff not needed here).
--2. Set a JVM option -Dsikuli.Debug=3 when running the exe to get more details about what's going on. I guess the problem is, that for some reason the export of the native libs does not work in the context of a launch4J exe (I did not test this yet).
--3. always use the latest version (1.1.1 in this case, still nightly but pre-final ;-) http://sikulix.com

Lambda Netbeans 7.4 JavaSE 8 Build 99 throws Error: Could not find or load main class

i have download Netbeans 7.4 Beta version which have J2SE 8 Support according to https://netbeans.org/community/releases/74/relnotes.html as well jdk-8-ea-bin-b99-windows-x64-18_jul_2013 install Java later Netbeans using the latest Java JDK everything was working smoothly i create a project later a class a main method code
System.out.println("running java 8");
and it works but lately i try to run my first simple Lambda and throws
Error: Could not find or load main class javase8.JavaSE8
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
i download the netbeans only the JavaSE version only for JavaSE8 testing but dont works..
i have try to clean and build change the directory of the project clean the cache Restart Netbeans and nothing happens. I haven't able to run my first Lambda what is wrong this is driving me nuts..
here is my simple code.
package javase8;
public class JavaSE8
{
public static void main(String[] args)
{
System.out.println("running main.");
Runnable r = ()->{System.out.println("running runnable...");};
//Thread t = new Thread(r);
// t.start();
}
}
if i remove the line
Runnable r = ()->{System.out.println("running runnable...");};
it works.
This lamdba expresion is created by Netbeans compiler itself after a anonymous inner class
the project on Run is enable to run under JavaSE8 as well their source Binary Format.
i have posted a video to show what i am doing please take a look.
Video

new Rengine(...); fails without error

I'm trying to set up JRI with Eclipse on a Windows 7 x64 system. I tried it once on my Laptop and it worked. Now on my Desktop it fails although everything of the R, rJava and JRI installation is exactly the same.
I set the JRI and R Paths correctly to:
C:\Program Files\R\R-2.15.1\library\rJava\jri;C:\Program Files\R\R-2.15.1\bin\x64
Also I set R_DOC_DIR etc in Eclipse.
Every time I try to run new Rengine(...); it fails without any error or exception. Debugging revealed an: <terminated, exit value: 10>C:\Program Files\Java\jre6\bin\javaw.exe (01.10.2012 18:00:31)
Is there anything I can try? It really bothers me that it works an my Laptop but not on my Workstation despite the same settings everywhere.
Edit: The code that is used to get the Rengine object.
public static Rengine getRengine(){
if (re == null) createRengine();
return re;
}
public static void createRengine(){
if (re!=null) return;
try{
if (!Rengine.versionCheck()) {
System.err.println("** Version mismatch **");
System.exit(1);
}
String[] arguments = {"--save"};
re=new Rengine(arguments, false, null);
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
}
catch (Exception e){
e.printStackTrace();
}
}
Edit: The last time i tried it i got an errormessage (creating of the REngine worked, this happened never before), R was missing a registryentry. After installing R 2.15.1 again it suddenly worked. Now after a restart it's the same like before. The program crashes at the creation of the REngine.
I was having the exact same problem. It turns out I had unchecked the box that asks to make a registry entry with the R version number. Once I let the installer run with that box checked, it seemed to work.
I would make sure your regedit looks like this:
Next up: getting this working in a portable way...
I am using R 3.2.2 and eclipse Mars on Windows 10 x64.
I faced the described issue today and tried around a bit. Finally, I found the root cause in the build path. Please check whether the following conditions are fulfilled:
1.) The following Java libraries from the JIRI folder on your hard disk shall be included as (user) libraries:
JIRI.jar
REngine.jar
JRIEngine.jar
2.) The native library jiri.dll is located in the subfolder "i386" for x86, whereas for x64 it is available in the subfolder "x64". The relevant one shall be added as separate native library location to the Java Build Path of the eclipse project. Otherwise, the file may not be considered as it is not located in the main JIRI folder.
Best regards
Philipp

Java project was running, but when I'm trying to build it I have NullPointerException at startsWith (NetBeans)

I have a next problem. When I'm running project from NetBeans IDE evrything is fine. But when I'm trying to build the project I have exception:
Compiling 2 source files to D:\JAVA\Projects\streamer\build\classes
An exception has occurred in the compiler (1.7.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at java.lang.String.startsWith(String.java:1433)
at java.lang.String.startsWith(String.java:1462)
at com.sun.tools.javac.file.SymbolArchive.addZipEntry(SymbolArchive.java:49)
at com.sun.tools.javac.file.ZipArchive.<init>(ZipArchive.java:63)
at com.sun.tools.javac.file.SymbolArchive.<init>(SymbolArchive.java:41)
............
D:\JAVA\Projects\streamer\nbproject\build-impl.xml:603: The following error occurred while executing this line:
D:\JAVA\Projects\streamer\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
I'm not use String.startsWith method, but I'm use String.indexOf in one place:
int lastIndex = nodeName.indexOf("date",0);
if (lastIndex != -1 || nodeName.equals("birthday")) {
txt_val = getHash(txt_val,Boolean.TRUE);
} else {
txt_val = getHash(txt_val,Boolean.FALSE);
}
nodeName is not null. And I couldn't understand where is an error :(
Did you use Java 7 intentionally? Try Java 6 - it should be more stable. Look here Change JRE in NetBeans project
Error is in compiler like the exception sayes. Why are you using java 1.7?

Categories